繁体   English   中英

PHP,如何获取特定号码?

[英]PHP, How can I retrieve a specific number?

我需要从URL地址检索iTunes应用程序ID。

https://itunes.apple.com/us/app/angry-birds-star-wars/id557137623?mt=8

我使用了strpos(),但是这个没有用。

如何从该地址获取ID后面的数字?

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

$ result ='557137623'

结果将是这样的。

$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
// 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始终具有这种形式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM