我有一个带有 xml 标头和 xml 代码的 php 文件,名为 test.php。
<?php
header('Content-type: text/xml');
$file = file_get_contents('http://api.tradedoubler.com/1.0/vouchers.xml?token=removed');
echo $file;
?>
API 中的 xml 如下所示:
<voucherList>
<voucher>
<id>115</id>
<programId>111</programId>
<programName>Program 111</programName>
<code>AF30C5</code>
<updateDate>1332422674941</updateDate>
<startDate>1332370800000</startDate>
<endDate>1363906800000</endDate>
<title>Voucher number one</title>
<shortDescription>Short description of the voucher.</shortDescription>
<description>This is a long version of the voucher description.</description>
<voucherTypeId>1</voucherTypeId>
<defaultTrackUri>http://clk.tradedoubler.com/click?a(222)p(111)ttid(13)</defaultTrackUri>
<siteSpecific>True</siteSpecific>
</voucher>
<voucher>
<id>116</id>
<programId>111</programId>
<programName>Program 111</programName>
<code>F90Z4F</code>
<updateDate>1332423212631</updateDate>
<startDate>1332370800000</startDate>
<endDate>1363906800000</endDate>
<title>The second voucher</title>
<shortDescription>Short description of the voucher.</shortDescription>
<description>This is a long version of the voucher description.</description>
<voucherTypeId>1</voucherTypeId>
<defaultTrackUri>http://clk.tradedoubler.com/click?a(222)p(111)ttid(13)url(http://www.example.com/product?id=123)</defaultTrackUri>
<siteSpecific>False</siteSpecific>
<landingUrl>http://www.example.com/product?id=123</landingUrl>
</voucher>
</voucherList>
如何将此文件加载为 xml?
以下不起作用:
$xml = simplexml_load_file('test.php');
echo $xml;
我只是得到一个白页。
测试文件保存为 php,因为它是动态的。它正在从 tradedoubler api 加载数据。
也许这是加载api数据的方式?