使用正则表达式从php字符串中的url提取整数

使用正则表达式从php字符串中的url提取整数,php,regex,Php,Regex,我有一个url,如下面的示例 http://www.website.com/page.php?pid=263547322425&foo=too 如何使用正则表达式获取pid的值。也就是说,在Perl中,从pid=的末尾到&?的值 $matches = array(); if (preg_match('/pid=(\d+)/', $url, $matches)) { echo $matches[1]; // pid value } if($line =~ /.+?pid=([0

我有一个url,如下面的示例

http://www.website.com/page.php?pid=263547322425&foo=too
如何使用正则表达式获取pid的值。也就是说,在Perl中,从pid=的末尾到&?

的值

$matches = array();
if (preg_match('/pid=(\d+)/', $url, $matches)) {
    echo $matches[1]; // pid value
}
if($line =~ /.+?pid=([0-9]+)\&/){
$pid = $1;
}
编辑:抱歉,没有看到PhP标记(我是新的:()

提供了一种简洁的方法:

$str = 'http://www.website.com/page.php?pid=263547322425&foo=too';
parse_str($str);
echo $pid;