PHP,如何检索特定的数字?

PHP,如何检索特定的数字?,php,Php,我需要从URL地址检索itunes应用程序id 我使用了strpos(),但这个不起作用 如何从该地址获取id后的号码 $url='1https://itunes.apple.com/us/app/angry-birds-star-wars/id557137623?mt=8'; $result='557137623' 结果会像这样 // Find where the / is and add 2 for the word "id" $pos = strrpos($url, "/") + 2;

我需要从URL地址检索itunes应用程序id

我使用了strpos(),但这个不起作用

如何从该地址获取id后的号码

$url='1https://itunes.apple.com/us/app/angry-birds-star-wars/id557137623?mt=8';

$result='557137623'

结果会像这样

// 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);

当然,这是假设您的URL始终具有此表单。

使用正则表达式@YousufIqbal将URL放入注释中,它的
[name](URL)
。您可以使用strpos来实现这一点(尽管不是最好的工具)。。给我们看看你的代码我为什么可以在这个问题上扣分?是不是因为我没有把所有的密码都写进去?我想最好解释一下我在找什么。我查找了PHP命令,但没有找到。我想,这是因为stackoverflow的人在RegEx问题再次出现时往往会有点生气;)
$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