Home > Article > Backend Development > How to get parameters in url in PHP
How PHP gets the parameters in the url: First create a PHP sample file; then get the specified url parameters through the "parse_url($url);" method.
#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
php Obtaining the parameter information in the url is one of the common test points in the PHP interview process. It is also a function that often needs to be implemented in our daily project development process. We can use parse_url and other related functions in PHP to accomplish.
So for PHP novices, how to implement it may be difficult, but it is actually very simple.
Let's use a simple example to introduce how PHP gets the parameters in the url.
The code example is as follows:
<?php $url = '//m.sbmmt.com/vip.html'; $url=parse_url($url); echo '协议 : '.$url['scheme']."<br>"; echo '主机 : '.$url['host']."<br>"; echo '路径 : '.$url['path']."<br>";
The result of obtaining the url parameters is as shown below:
As shown in the figure, we obtained //m.sbmmt.com/vip.htmlAll parameters of this url, such as protocol, host, and path.
For example, we get the parameters of the URL //m.sbmmt.com/jishu/php/413303.html:
where parse_url functionParses the URL and returns its components.
Note: For severely unqualified URLs, parse_url() may return FALSE.
This article is an introduction to the method of obtaining the parameters in the URL in PHP. It is very simple and easy to understand. I hope it will be helpful to friends in need!
The above is the detailed content of How to get parameters in url in PHP. For more information, please follow other related articles on the PHP Chinese website!