Home >Backend Development >PHP Problem >How to convert php array into url parameters

How to convert php array into url parameters

藏色散人
藏色散人Original
2020-09-28 10:28:252860browse

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.

How to convert php 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 = &#39;http://username:password@hostname/path?arg=value#anchor&#39;;
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does php vc14 mean?Next article:What does php vc14 mean?