我需要从URL地址检索itunes app id。
https://itunes.apple.com/us/app/angry-birds-star-wars/id557137623?mt=8
我使用了strpos(),但这个没用。
如何从此地址获取身份后的号码?
$ url ='https://itunes.apple.com/us/app/angry-birds-star-wars/id557137623?mt=8';
$ result ='557137623'
结果就像这个。
答案 0 :(得分:3)
$url = 'https://itunes.apple.com/us/app/angry-birds-star-wars/id557137623?mt=8';
preg_match("~id(\d+)~", $url, $matches);
$result = $matches[1];
echo $result; //557137623
答案 1 :(得分:1)
// Find where the / is and add 2 for the word "id"
$pos = strrpos($url, "/") + 2; // Note that it's "strrpos" not "strpos"
// Find the question mark at the end
$pos2 = strpos($url, "?");
$id = substr($url, $pos, $pos2 - $pos);
当然,这是假设您的网址始终包含此表单。