簡體   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