Use regex to extract integer from url in a string with php
I have a url such as the example below
http://www.website.com/page.php?pid=263547322425&foo=too
How can i use regex to get the value of pid. Thats to say the value from the e开发者_如何学运维nd of pid= until the &?
$matches = array();
if (preg_match('/pid=(\d+)/', $url, $matches)) {
echo $matches[1]; // pid value
}
parse_str
provides a neat way to do that:
$str = 'http://www.website.com/page.php?pid=263547322425&foo=too';
parse_str($str);
echo $pid;
in Perl
if($line =~ /.+?pid=([0-9]+)\&/){
$pid = $1;
}
EDIT: Sorry didn't see the PhP tag (I'm new :( )
精彩评论