从这样的 URL 仅获取B005PB3YHU部分 的最佳方法是什么: http ://www.amazon.com/Designer-Bow-Ties-Y306/dp/B005PB3YHU%3FSubscriptionId%3DAKIAIM6KP3HMBKZXA2EA%26tag%3Dmenbowtie-20%26linkCode% 3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB005PB3YHU
问问题
191 次
2 回答
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'];
于 2012-09-21T22:29:40.703 回答
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'];
于 2012-09-21T22:45:06.737 回答