This article adds several url encoding parsing functions in php, such as parse_url, rawurldecode, rawurlencode, urldecode, and urlencode.
This article has added several url encoding parsing functions, such as parse_url, rawurldecode, rawurlencode, urldecode, and urlencode.
The following describes the introduction and examples.
Parse_url ($ str url );
Convert a url into an array
*/
Print_r (parse_url ("www. bKjia. c0m"); // parse the url and output the returned array
/*
Returns a string in special url format to a normal string.
Syntax: string rawurldecode (string str );
Return Value: String
Function Type: Encoding
Description
This function decodes strings. Parses the string from the special format of the url into a normal string. For detailed encoding and decoding information and specification files, refer to rfc 1738.
*/
Echo rawurldecode ('foo % 20bar % 40baz'); // output foo bar @ baz
/*
String rawurlencode (string str)
Returns a string. All non-alphanumeric characters except-_. In this string will be replaced with a semicolon (%) followed by two hexadecimal numbers. This encoding is described in rfc 1738 to protect the original characters from being interpreted as special url delimiters and protect the url format to prevent them from being transmitted to media (like some email systems) use character conversion. For example, if you want to include a password in an ftp url:
*/
$ Str = "http://www.bKjia. c0m"; // defines a string
$ Result = rawurlencode ($ str); // encode the specified string
Echo $ result;
/*
Urldecode ()
Url Decoding
* /// Output result
$ Str = "http % 3a % 2f % 2fwww. bKjia. c0m ";
$ Result = urldecode ($ str );
Echo $ result;
/*
Urlencode ()
Url Encoding
*/
$ Str = "http://www.bKjia. c0m"; // defines a string
$ Result = urlencode ($ str); // encode the specified string
Echo $ result; // output result