这几天我正在研究易趣api,但我还是想不出如何使用完整的商品url(http://www.ebay.com/ctg/TomTom-XXL-550M-US-including-Puerto-Rico-Canada-Mexico-Automotive-GPS-Receiver-/86127922?)来获取易趣商品id。
我尝试了很多方法,但是否定的请帮帮我!有什么可以使用的apis吗?或者其他任何方式,我只需要易趣的商品编号..
发布于 2012-05-02 06:02:02
这没有经过测试,只是很快就写出来了。它至少应该给你一个大概的概念。它假定id将始终是最后一个/之后的url段。如果不是这样,这个答案将是非常无用的。
$ebayUrl = "http://www.ebay.com/ctg/TomTom-XXL-550M-US-including-Puerto-Rico-Canada-Mexico-Automotive-GPS-Receiver-/86127922?";
$pos = strrpos($ebayUrl, '/') + 1;
$id = substr($ebayUrl, $pos);
//if you want to remove the question mark left at the end
$id = str_replace("?", "", $id);
echo $id;发布于 2012-05-02 06:39:57
其他替代方案可以是:
$parts = explode('/', 'http://www.ebay.com/ctg/TomTom-XXL-550M-US-including-Puerto-Rico-Canada-Mexico-Automotive-GPS-Receiver-/86127922?');
$id = trim(end($parts), '?');
echo $id;发布于 2016-06-14 14:15:28
根据需要执行此操作的位置,您可以使用ebayItemID
例如(javascript) var itemid = ebayItemID;
我使用此方法在产品描述中添加了一个“立即购买”按钮。
https://stackoverflow.com/questions/10404953
复制相似问题