Home > Backend Development > PHP Tutorial > PHP parses url to get parameter values ​​in url

PHP parses url to get parameter values ​​in url

angryTom
Release: 2023-04-07 15:20:01
forward
3793 people have browsed it

This article will introduce you to how PHP parses the url and gets the parameters in the url and how to get the url parameters. The code in this article is simple and easy to understand. Friends who are interested can take a look.

The code is as follows

$url = 'http://www.baidu.com/index.php?
m=content&c=index&a=lists&catid=6&area=0&author=0&h=0®ion=0&s=1&page=1';
parse_str(parse_url($url)[query],$query_arr);
var_dump($query_arr);
Copy after login

Result

array (size=10)
          'm' => string 'content' (length=7)
          'c' => string 'index' (length=5)
          'a' => string 'lists' (length=5)
          'catid' => string '6' (length=1)
          'area' => string '0' (length=1)
          'author' => string '0' (length=1)
          'h' => string '0' (length=1)
          'region' => string '0' (length=1)
          's' => string '1' (length=1)
          'page' => string '1' (length=1)
Copy after login

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of PHP parses url to get parameter values ​​in url. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:www.phplaozhang.com
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