您也可以下载数据,使用类似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
;-)
我一直对你的答案的质量和细节印象深刻。 – 2009-09-25 20:33:58
因此为什么15k代表 – alexus 2009-09-25 21:12:51
@Franck:谢谢! @Alexus:也谢谢:-) – 2009-09-25 21:49:09