Home >Backend Development >PHP Tutorial >Introduction to the difference between php urlencode and rawurlencode_PHP tutorial
In PHP, both rawurlencode and rawurlencode encode characters. Let me introduce to you the difference between urlencode and rawurlencode. Friends who need to know can refer to it.
The purpose of urlencode is to encode a string and replace all non-alphanumeric characters except "-_" in the original string with a percent sign (%) followed by two hexadecimal digits. However, please note: For historical reasons, spaces will be replaced with + signs. Rawurlencode is actually the same as urlencode, and is also used to encode strings. The only difference is that it uses RFC1738 encoding, which means that spaces are replaced with %20.
Their corresponding decoding functions are urldecode and rawurldecode. Referring to the instructions on the official website, any %## and plus sign ('+') in the encoded string given by urldecode decoding are decoded into a space character; rawurldecode decodes the percent sign (%) in the character string followed by two Bit hexadecimal. There are two differences. First, urldecode will decode any two characters after the percent sign (%). For example, %MN will also be decoded, but it will fail; rawurldecode will only decode the percent sign (%). Only the last two characters in hexadecimal (0-9A-F) will be decoded. Second, urldecode will decode the + sign into a space.
Let’s take a look at the official introduction of the two functions in PHP.
urlencode — encode a URL string
Report a bug Description
string urlencode ( string $str )
This function makes it easy to encode a string and use it in the request part of the URL, and it also makes it easy to pass variables to the next page.
Report a bug parameter
str
The string to encode.
Report a bug return value
Returns a string in which all non-alphanumeric characters except -_. are replaced with a percent sign (%) followed by two hexadecimal digits, and spaces are encoded as plus signs (+). This encoding is the same as the encoding of WWW form POST data, and the same encoding as the application/x-www-form-urlencoded media type. For historical reasons, this encoding differs from the RFC1738 encoding (see rawurlencode()) in encoding spaces as plus signs (+).
The code is as follows
|
Copy code
echo '';
echo '';
Example #1 在 FTP URL 里包含一个密码
echo '';
|