This article mainly introduces PHP commonly used URL processing function, the example summarizes the Parse_url, Rawurldecode, UrlEncode, UrlDecode and some more commonly used URL processing functions, very practical value, the need for friends can refer to the next
This paper summarizes several parsing functions of URL encoding in PHP, such as Parse_url, Rawurldecode, Rawurlencode, UrlDecode, UrlEncode. Share it for everyone's reference. The specific usage is as follows:
The following is an introduction and an example: Parse_url ($str URL);
Convert URL to array: Print_r (Parse_url ("www.jb51.net")); Resolves the URL and outputs the returned array, and the URL-specific format string is restored to a normal string.
Syntax: string rawurldecode (String str);
return value: String
Function type: Encoding processing
Description: This function decodes the string, from the URL of the special format of the string to the ordinary string, the detailed encoding and decoding information and specification file can refer to RFC 1738, the code is as follows:
The code is as follows:
echo rawurldecode (' Foo%20bar%40baz '); Output foo Bar@baz string Rawurlencode (String str)
Returns a string, in addition to-_, in this string. All non-alphanumeric characters will be replaced with a percent (%) followed by a two-digit hexadecimal number, which 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 from transmitting media, like some messaging systems, Use character conversions when confusing, for example, if you want to include a password in the FTP URL:
The code is as follows:
$str = "Http://www.jb51.net"; Defines the string $result =rawurlencode ($STR); Encodes the echo $result for the specified string; /* UrlDecode () URL decoding/ ////Output $STR = "Http%3a%2f%2fwww.jb51.net"; $result =urldecode ($STR); echo $result;/* UrlEncode () URL code */$str = "http://www.jb51.net"; Defines the string $result =urlencode ($STR); Encodes the echo $result for the specified string; Output results