This article summarizes several URL-coded parsing functions in PHP, such as Parse_url, Rawurldecode, Rawurlencode, UrlDecode, and UrlEncode. Share for everyone's reference. The specific usage is as follows:
Here is a look at the introduction and example: Parse_url ($str URL);
Converts the URL to an array: Print_r (Parse_url ("www.jb51.net")); Resolves the URL and outputs the returned array, and the URL private format string is restored to a normal string.
Syntax: string rawurldecode (String str);
return value: String
Function type: Encoding processing
Description: This function will decode the string, from the URL of the special format of the string into ordinary strings, detailed coding and decoding information and specifications can refer to RFC 1738, the code is as follows:
Copy Code code as follows:
echo rawurldecode (' Foo%20bar%40baz '); Output Foo Bar@baz
String Rawurlencode (String str)
Returns a string, in addition to the-_ in this string. All non-alphanumeric characters are replaced with a percent semicolon (%) followed by a two-digit hexadecimal number. This is the encoding described in RFC 1738 to protect the literal character from being interpreted as a special URL delimiter, while protecting the URL format so that it is not transmitted to the media, like some mail systems, Use character conversion when messing with, for example, if you want to include a password in the FTP URL:
Copy Code code as follows:
$str = "Http://www.jb51.net"; Define String
$result =rawurlencode ($STR); Encodes the specified string
echo $result;
/*
UrlDecode ()
URL decoding
*///Output results
$str = "Http%3a%2f%2fwww.jb51.net";
$result =urldecode ($STR);
echo $result;
/*
UrlEncode ()
URL encoding
*/
$str = "Http://www.jb51.net"; Define String
$result =urlencode ($STR); Encodes the specified string
echo $result; Output results
I hope this article will help you with your PHP program design.