test.php という名前の xml ヘッダーと xml コードを含む 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-dataがロードされる方法ですか?