php 怎么获取匹配解析当前网址中的参数

WBOY
Release: 2016-06-20 12:27:15
Original
949 people have browsed it

比如有一个网址为

http://域名/goods.php?u=59&id=24#pinglun

我想得到24这个id值怎么办.

可以用正则,也可以用php函数解析到数组中

用正则可以这样

preg_match('/id=(\d+)/',$_SERVER["REQUEST_URI"],$m);//$_SERVER 这个表示当前网址urlprint_r($m[1]);exit;
Copy after login

或者用parse_url()及parse_str()函数

$cur_q=parse_url($_SERVER["REQUEST_URI"],PHP_URL_QUERY);parse_str($cur_q,$myArray);print_r($myArray["id"]);exit;
Copy after login

 

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