我在這裏使用的是Amazon Affiliate API。實際上,我對這一切都相當陌生。使用simplexml_load_file()從亞馬遜附屬API的xml文件中獲取屬性
我有PHP代碼來生成產品的工作URL,但我有問題從該網址生成的XML中提取數據。我正在尋找從XML返回FormattedPrice。
下面是XML文件的例子: https://pastebin.com/HnttEVfv
這裏是我的代碼試圖拉「FormattedPrice」。下面的例子都沒有工作,只是返回空值。
旁註:$ request_url是xml文件的完整http://有效url。
$getxml = simplexml_load_file($request_url);
$price = $getxml->ItemLookupResponse->Items->Item->ItemAttributes->ListPrice['FormattedPrice'];
也不
$price = $getxml->ItemLookupResponse->Items->Item->ItemAttributes->ListPrice->FormatedPrice;
file_get_contents($ request_url)是否返回一些內容? –
如果它確實將XML的內容作爲字符串返回,那麼您可以僅使用simplexml_load_string(file_get_contents($ request_url))。 –
var_dump($ getxml);轉儲然而,當我嘗試去「FormattedPrice」我似乎無法得到的價格代碼拉XML.file_get_contents($ request_url)返回一個字符串的整個xml是;然而包裝在加載字符串不起作用。 – fullninja