从这样的网址中仅获取 B005PB3YHU 部分的最佳方式是什么? : http://www.amazon.com/Designer-Bow-Ties-Y306/dp/B005PB3YHU%3FSubscriptionId%3DAKIAIM6KP3HMBKZXA2EA%26tag%3Dmenbowtie-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB005PB3YHU
答案 0 :(得分:4)
使用parse_url
和parse_string
:
http://php.net/manual/en/function.parse-url.php
http://php.net/manual/en/function.parse-str.php
$query = parse_url($url,PHP_URL_QUERY);
parse_str($query,$parts);
echo $parts['creativeASIN'];
答案 1 :(得分:1)
在@ jimp的答案的基础上,你需要首先urldecode将%##更改为PHP理解的东西:
$url = 'http://www.amazon.com/Designer-Bow-Ties-Y306/dp/B005PB3YHU%3FSubscriptionId%3DAKIAIM6KP3HMBKZXA2EA%26tag%3Dmenbowtie-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB005PB3YHU';
# urldecode will remove the %## encoding, and make the url look like:
# http://www.amazon.com/Designer-Bow-Ties-Y306/dp/B005PB3YHU?SubscriptionId=AKIAIM6KP3HMBKZXA2EA&tag=menbowtie-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B005PB3YHUB005PB3YHU
$query = parse_url(urldecode($url), PHP_URL_QUERY);
parse_str($query, $parts);
echo $parts['creativeASIN'];