您可以使用类似的东西下载数据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