PHP development skills (9) - How to obtain various parameters in the url

黄舟
Release: 2023-03-06 13:52:01
Original
1698 people have browsed it

In normal website development, we must deal with URLs. We can access specific addresses through URLs, and pass the parameters we need to test through URLs. Therefore, how to obtain the parameters in the URL becomes important. This blog post will explain how to get the parameters in the URL. This is just a function method that gets the parameters by passing the complete URL address string. The following is the code:

<?php  
  
/** 
 * ======================================= 
 * Created by Zhihua_W. 
 * Author: Zhihua_W 
 * Date: 2017/1/3 0009 
 * Time: 上午 11:03 
 * Project: PHP开发小技巧 
 * Power: 获取url中的各个参数 
 * ======================================= 
 */  
  
/** 
 * 获取url中的各个参数 
 * 类似于 pay_code=alipay&bank_code=ICBC-DEBIT 
 * @param type $str 
 * @return type 
 */  
function parse_url_param($str)  
{  
    $data = array();  
    $parameter = explode(&#39;&&#39;, end(explode(&#39;?&#39;, $str)));  
    foreach ($parameter as $val) {  
        $tmp = explode(&#39;=&#39;, $val);  
        $data[$tmp[0]] = $tmp[1];  
    }  
    return $data;  
}  
  
?>
Copy after login


The above is the detailed content of PHP development skills (9) - How to obtain various parameters in the url. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!