我有这个网址,我想只获取其.ipa
文件所在部分的网址:
因此,我只想要这个:
的http%3A%2F%2fhot.haima.me%2fee%2f201702%2f1776%2fcom.imagility.evergrow_12020_20170217141048_3_fp1q5w.ipa
然后我希望它被解码,所以我想最终得到:
http://hot.haima.me/ee/201702/1776/com.imagility.evergrow_12020_20170217141048_3_fp1q5w.ipa
我希望此URL位于变量中。它是API中对象的一部分,因此访问第一个非常长的URL就像$jsonRoot->data->app1->ipaURL
。
答案 0 :(得分:3)
使用函数将字符串解析为变量。它将为您解码:
parse_str(parse_url($url, PHP_URL_QUERY), $vars);
echo $vars['u'];
parse_url()
获取查询字符串parse_str()
解析$vars
u
$vars
索引
收率:
http://hot.haima.me/ee/201702/1776/com.imagility.evergrow_12020_20170217141048_3_fp1q5w.ipa
假设在u
中找到了该网址。如果没有,那就grep吧:
echo current(preg_grep('/\.ipa/', $vars));
答案 1 :(得分:0)
看看这个简单的演示:
<?php
$input = 'http://sdl.haima.me/dl.ashx?s=8b000d38-3605-418b-8eb9-37d57f4ba24d&b=com.imagility.evergrow&v=12020&u=http%3a%2f%2fhot.haima.me%2fee%2f201702%2f1776%2fcom.imagility.evergrow_12020_20170217141048_3_fp1q5w.ipa&m=81e26501dc93bc73bec5ae8f1e7cb3c5&k=';
$query = parse_url($input, PHP_URL_QUERY);
foreach (explode('&', $query) as $arg) {
list($key, $val) = explode('=', $arg);
if ('u'===$key) {
echo urldecode($val);
}
}
输出显然是:
http://hot.haima.me/ee/201702/1776/com.imagility.evergrow_12020_20170217141048_3_fp1q5w.ipa