Php 读特定单词后的数字
我试图在php中读取链接中的数字。但我不知道怎么做Php 读特定单词后的数字,php,Php,我试图在php中读取链接中的数字。但我不知道怎么做 http://example.com/Productdetail.asp?SID=72&ProductID=8640 如果不同时读取72,我如何读取编号8640 ProductID=您可以使用explode() 简单使用 echo $_GET['ProductID'];//8640 您可以使用preg\u match作为 $str = "http://example.com/Productdetail.asp?SID=72&
http://example.com/Productdetail.asp?SID=72&ProductID=8640
如果不同时读取72
,我如何读取编号8640
ProductID=
您可以使用explode()
简单使用
echo $_GET['ProductID'];//8640
您可以使用preg\u match
作为
$str = "http://example.com/Productdetail.asp?SID=72&ProductID=8640";
preg_match('/&ProductID=(\d+)?/',$str,$match);
echo $match[1];
$str = "http://example.com/Productdetail.asp?SID=72&ProductID=8640";
parse_str($str,$res);
echo $res['ProductID'];
或者您可以简单地使用parse_str
as
$str = "http://example.com/Productdetail.asp?SID=72&ProductID=8640";
preg_match('/&ProductID=(\d+)?/',$str,$match);
echo $match[1];
$str = "http://example.com/Productdetail.asp?SID=72&ProductID=8640";
parse_str($str,$res);
echo $res['ProductID'];
您可以使用:
要获取ProductID,请执行以下操作:
指数
从ProductID=获取字符串直到字符串结束
要替换ProductID=零件