Home > php教程 > PHP源码 > 【PHP伪静态】时获取不规则的URL参数

【PHP伪静态】时获取不规则的URL参数

PHP中文网
Release: 2016-05-25 17:07:57
Original
1709 people have browsed it

使用【PHP伪静态】时,想要获取不规则的URL参数是比较麻烦,比如:
/article/category-5/author-1086/page-12
/article/author-1086
/article/category-5
下面这段代码可以帮大家解决问题。

$url = explode('/', '/article/category-5/status-2/page-3');       
$params = array();        
foreach ($url as $v)
{
    $temp = explode('-', $v);
    if (isset($temp[1]))
        $params[$temp[0]] = $temp[1];
}
var_dump($params);
Copy after login
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template