How to convert php array into url parameters: first create a PHP sample file; then define an array; finally, use the "http_build_query($array)" method to convert the array into URL parameters.
Recommended: "PHP Video Tutorial"
php Convert Array to URL Parameters
$array =array ( 'id' =123, 'name' = 'dopost' ); echo http_build_query( $array ); //得到结果 id=123name=dopost
An example is as follows:
The code is as follows:
$url = "http://www.electrictoolbox.com/php-extract-domain-from-full-url/"; $parts = parse_url($url);
Output:
The code is as follows:
Array ( [scheme] => http [host] => www.electrictoolbox.com [path] => /php-extract-domain-from-full-url/ )
Another example:
The code is as follows:
<?php $url = 'http://username:password@hostname/path?arg=value#anchor'; print_r(parse_url($url)); echo parse_url($url, PHP_URL_PATH); ?>
Output:
The code is as follows:
Array ( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor )
The above is the detailed content of How to convert php array into url parameters. For more information, please follow other related articles on the PHP Chinese website!