tags:

views:

106

answers:

3

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 end of pid= until the &?

+7  A: 
$matches = array();
if (preg_match('/pid=(\d+)/', $url, $matches)) {
    echo $matches[1]; // pid value
}
OcuS
+1  A: 

in Perl

if($line =~ /.+?pid=([0-9]+)\&/){
$pid = $1;
}

EDIT: Sorry didn't see the PhP tag (I'm new :( )

dangerstat
+6  A: 

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;
karim79