Home >Backend Development >PHP Tutorial >Summary of url processing functions in php_PHP tutorial
There are many url processing functions in PHP, such as: http_build_query, compact, urldecode, urlencode, parse_url, rawurldecode and other functions.
http_build_query
(PHP 5) http_build_query — Generate URL-encoded request string
The code is as follows | Copy code | ||||
'baz'=>'boom', 'cow'=>'milk', 'php'=>'hypertext processor');echo http_build_query($data); // foo=bar&baz=boom&cow=milk&php=hypertext+processor ?>
|
代码如下 | 复制代码 |
$city = "San Francisco"; $qs=compact('province','city','name'); |
array compact ( mixed $varname [, mixed $... ] )
(PHP 4, PHP 5) compact — Create an array including variable names and their values
The code is as follows | Copy code | ||||
$city = "San Francisco"; $state = "CA";
$result = compact("city", "state", "event"); // array('city'=>'"San Francisco"','state'=>'CA','event' => "SIGGRAPH")?> -------------$qs=compact('province','city','name');
foreach($qs as $key => $value){
} |
代码如下 | 复制代码 |
*/ echo rawurldecode('foo%20bar%40baz'); //输出foo bar@baz string rawurlencode ( string str ) |
The code is as follows | Copy code |
*/ print_r(parse_url("www.bKjia.c0m")); //Parse the url and output the return array /* |
The code is as follows | Copy code |
*/ echo rawurldecode('foo%20bar%40baz'); //Output foo bar@baz /* string rawurlencode ( string str ) |
Returns a string in which all non-alphanumeric characters except -_. are replaced with a percent sign (%) followed by two hexadecimal digits. This is an encoding described in rfc 1738, and is intended to protect literal characters from being interpreted as special URL delimiters, and to protect the URL format from being garbled by character conversions used by the transport medium (like some mail systems). For example, if you want to include the password in the ftp url:
The code is as follows
|
Copy code | ||||
$result=rawurlencode($str); //Encode the specified string
url encoding */