ste*_*tef 3 php regex url url-parameters
在下面的网址中,我想获得ProdId的价值.URL格式将始终保持一致,参数名称也将保持一致,但值的长度可能会更改.它始终是数字.
http://www.example.com/page.php?ProdId=2683322&xpage=2
Run Code Online (Sandbox Code Playgroud)
使用PHP获取它的最快方法是什么(我将处理10,000的速度是一个问题)?
Mik*_*e B 13
PHP具有内置函数.使用parse_url()和parse_str()在一起.
从php.net拼凑而成:
$url = 'http://www.example.com/page.php?ProdId=2683322&xpage=2';
// Parse the url into an array
$url_parts = parse_url($url);
// Parse the query portion of the url into an assoc. array
parse_str($url_parts['query'], $path_parts);
echo $path_parts['ProdId']; // 2683322
echo $path_parts['xpage']; // 2
Run Code Online (Sandbox Code Playgroud)
试试这个正则表达式:
^http://www\.example\.com/page\.php\?ProdId=(\d+)
Run Code Online (Sandbox Code Playgroud)