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

How to convert php array into url parameters

藏色散人
Release: 2023-03-06 07:12:02
Original
2863 people have browsed it

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
Copy after login

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);
Copy after login

Output:

The code is as follows:

Array
(
[scheme] => http
[host] => www.electrictoolbox.com
[path] => /php-extract-domain-from-full-url/
)
Copy after login

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);
?>
Copy after login

Output:

The code is as follows:

Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template