【发布时间】:2017-07-25 15:21:01
【问题描述】:
我在这里使用 Amazon Affiliate API。实际上,我对这一切都很陌生。
我有 PHP 代码来为产品生成一个有效的 URL,但是我在从该 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 的字符串是的;但是包裹在加载字符串中不起作用。
标签: php xml amazon-web-services simplexml