次のようなものを使用して、データをダウンロードできますfile_get_contents
。単一の PHP 文字列で XML 全体を取得します。
例えば :
$xml = file_get_contents('http://twitter.com/statuses/user_timeline/31139114.rss');
$xml
XML 文字列が含まれるようになりました。
次に、を使用して、その文字列をファイルに書き込むことができますfile_put_contents
。
例えば :
file_put_contents('/home/squale/developpement/tests/temp/test.xml', $xml);
そして、ファイルを確認するには、コマンドラインから:
$ cat test.xml
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>Twitter / eBayDailyDeals</title>
<link>http://twitter.com/eBayDailyDeals</link>
<atom:link type="application/rss+xml" href="http://twitter.com/statuses/user_timeline/31139114.rss" rel="self"/>
<description>Twitter updates from eBay Daily Deals / eBayDailyDeals.</description>
<language>en-us</language>
<ttl>40</ttl>
<item>
...
...
その後、simplexml_load_file
そのファイルから読み取るために使用できます。
例えば :
$data = file_get_contents('/home/squale/developpement/tests/temp/test.xml');
そして$data
今、あなたのXML文字列が含まれています;-)
リモート サーバーから取得した XML が文字列であることを考慮すると、シリアル化する必要はありません。+ + ;-)よりfile_put_contents
も簡単ですfopen
fwrite
fclose