-1

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'

結果はこのようになります。

4

2 に答える 2

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
于 2012-11-14T01:48:59.137 に答える
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);

もちろん、これは、URLが常にこの形式であると想定しています。

于 2012-11-14T01:47:42.867 に答える