Expand description
Encodings: URL encoding, http_build_query, base64, hex, HTML entities
and quoted-printable.
Ported from PHP 8.5.11 (ext/standard/url.c, http.c, base64.c,
string.c, html.c, quot_print.c). Byte strings in, byte strings out;
encoders whose output is always ASCII return String.
| PHP | Rust |
|---|---|
urlencode, rawurlencode, urldecode, rawurldecode | urlencode, rawurlencode, urldecode, rawurldecode |
http_build_query | http_build_query with QueryEncoding |
parse_str | parse_str |
base64_encode, base64_decode | base64_encode, base64_decode |
bin2hex, hex2bin | bin2hex, hex2bin |
htmlspecialchars, htmlentities | htmlspecialchars, htmlentities with HtmlFlags |
quoted_printable_encode | quoted_printable_encode |
The HTML functions support PHP’s default charset, UTF-8. Their entity
tables (encoding/html_tables.rs) are generated by
data/html_entities.py from php-src’s ext/standard/html_tables.h and
PHP’s own get_html_translation_table() (data/html_entities.php).
Structs§
- Html
Flags - The
$flagsof the HTML functions, decoded from PHP’s bit mask.
Enums§
- Doctype
- The document type of the
ENT_HTML401/ENT_XML1/ENT_XHTML/ENT_HTML5flags. - Query
Encoding http_build_query()’s$encoding_type.
Constants§
- MAX_
INPUT_ NESTING_ LEVEL max_input_nesting_level: bracket levels in a variable name, PHP’s default.- MAX_
INPUT_ VARS max_input_vars: variables registered per input, PHP’s default.
Functions§
- base64_
decode - PHP
base64_decode($string, $strict). Non-strict skips every byte that is not in the alphabet (and decodes data after=padding); strict skips only\t \n \rand spaces and fails (None, PHP’sfalse) on anything else, on data after padding, on a lone final character or on bad padding. - base64_
encode - PHP
base64_encode: standard alphabet with=padding. - bin2hex
- PHP
bin2hex: lowercase hexadecimal. - hex2bin
- PHP
hex2bin:None(PHP’sfalse, with a warning) for an odd length or a non-hexadecimal character. - htmlentities
- PHP
htmlentities($string, $flags, 'UTF-8', $double_encode): likehtmlspecialcharsbut every character with a named entity in the doctype’s table is converted (HTML 4.01 and XHTML: 253 entities, HTML5: 1511 including two-character ones such asfj; XML 1.0: the basic ones). - htmlspecialchars
- PHP
htmlspecialchars($string, $flags, 'UTF-8', $double_encode): escapes& < >and the quotesflagsselects ('as'in HTML 4.01,'otherwise). Withdouble_encodefalse, existing valid entities are kept. Invalid UTF-8 followsENT_IGNORE/ENT_SUBSTITUTE, else the result is empty. - http_
build_ query - PHP
http_build_query($data, $numeric_prefix, $arg_separator, $encoding_type)for data decoded from JSON (objects are PHP arrays; keys that are canonical integers are integer keys, which getnumeric_prefixat the top level). Nested arrays becomea%5Bb%5D=...;nullvalues are skipped, booleans are1/0, floats use theprecisionsetting.arg_separatorNoneis PHP’sarg_separator.outputdefault,&. - is_
integer_ key - Whether a PHP array key string is an integer key (
ZEND_HANDLE_NUMERIC_STR):-?[1-9][0-9]*or0, withini64. - parse_
str parse_str($string, $result):php_default_treat_data(PARSE_STRING)with the defaultarg_separator.input(&),max_input_varsandmax_input_nesting_level. Also how Swoole fills$request->getand, forapplication/x-www-form-urlencodedbodies,$request->post.- quoted_
printable_ encode - PHP
quoted_printable_encode(RFC 2045, lines of at most 76 bytes with PHP’s look-ahead for multi-byte UTF-8 lead bytes). - rawurldecode
- PHP
rawurldecode:%XXis a byte (+stays+). - rawurldecode_
into rawurldecode, appended tooutinstead of a new buffer.- rawurlencode
- PHP
rawurlencode(RFC 3986): alphanumerics and-_.~are kept, every other byte is%XX. - register_
variable php_register_variable_ex($name, $value, $array): registers one request variable the way PHP fills$_GET,$_POSTand$_COOKIE. Leading spaces are dropped,.andin the base name become_,name[a][]builds nested arrays (at mostMAX_INPUT_NESTING_LEVELlevels; deeper names drop the whole variable), and an unterminated[is kept as_.- urldecode
- PHP
urldecode:+is a space and%XXa byte; a%not followed by two hex digits is kept. - urldecode_
into urldecode, appended tooutinstead of a new buffer.- urlencode
- PHP
urlencode:application/x-www-form-urlencoded(RFC 1738): alphanumerics and-_.are kept, a space is+, every other byte (including~) is%XX.