开发者

Use regex to extract integer from url in a string with php

开发者 https://www.devze.com 2022-12-18 03:51 出处:网络
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

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 :( )

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号