php - 从 url 获取 itunes id

标签 php regex

从 iTunes 应用程序链接检索 ID 的最佳方法是什么?

假设我有这些链接:

http://itunes.apple.com/us/app/bring-me-sandwiches!!/id457603026?mt=8

http://itunes.apple.com/us/app/bring-me-sandwiches!!/id457603026

我只想使用 php preg_match 获取 id,457603026

最佳答案

没有 preg_match:

$url = 'http://itunes.apple.com/us/app/bring-me-sandwiches!!/id457603026?mt=8';
echo end(explode('/id', parse_url($url, PHP_URL_PATH)));

或者,如果您愿意:

$url = 'http://itunes.apple.com/us/app/bring-me-sandwiches!!/id457603026?mt=8';
$id = explode('/id', parse_url($url, PHP_URL_PATH));
echo $id[1];

关于php - 从 url 获取 itunes id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8351655/

相关文章:

php - mysql查询以检查codeigniter中数组中是否存在字段

php - Docker:从一个容器中的应用程序和服务器登录

c# - 正则表达式在斜线之间得到一个词

Java正则表达式数学测试

php - Laravel 5.4 集合 sortByDesc 不工作

php - MYSQL查询的问题(效率)

java - 文件路径的 Ant Propertyregex 部分

C# - 获取目录中以特定格式开头的文件名

php - 在支持表格中包含日期、IP 和 HTTP_HOST

python - 具有lookbehind和lookahead的非捕获括号 - Python