Home > Backend Development > PHP Problem > How to convert the browser address bar string into an array in PHP

How to convert the browser address bar string into an array in PHP

王林
Release: 2023-03-12 16:44:01
Original
1759 people have browsed it

The method for php to convert the browser address bar string into an array is to use the parse_str() function, such as [parse_str($query_str,$query_arr);].

How to convert the browser address bar string into an array in PHP

The operating environment of this article: windows10 system, php 7, thinkpad t480 computer.

It is not difficult to convert strings and arrays in the browser address bar in PHP. As long as we make reasonable use of the functions provided by PHP, we can easily achieve it. Let’s take a look together below.

$data = array(
  'name' => 'tom',
  'sex' => 1,
  'channel' => 'ty'
);
Copy after login

Convert array to url parameter string

$queryStr = http_build_query($data);
 
echo query_str;
Copy after login

Execution result:

name=tom&sex=1&channel=ty
Copy after login

Convert url parameter string to array

parse_str($query_str,$query_arr);
 
print_r($query_arr);
Copy after login

Execution Result:

array(
  name => tom,
  sex => 1,
  channel => ty
)
Copy after login

Recommended learning: php training

The above is the detailed content of How to convert the browser address bar string into an array in PHP. 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