作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
如何在 PHP 中将 XML 文件打印到屏幕上?
这不起作用:
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, 'http://rss.news.yahoo.com/rss/topstories');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
curl_close ($curl);
$xml = simplexml_load_string($result);
echo $xml;
有简单的解决方案吗?也许没有 SimpleXML?
最佳答案
感谢 PHP's wrappers,您可以像使用本地文件一样使用 HTTP URL
您可以通过 file_get_contents() 从 URL 中获取内容,然后回显它,甚至可以使用 readfile() 直接读取它
$file = file_get_contents('http://example.com/rss');
echo $file;
或
readfile('http://example.com/rss');
不过,不要忘记在输出任何内容之前设置正确的 MIME 类型。
header('Content-type: text/xml');
关于php - 如何在 PHP 中回显 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1199595/
我是一名优秀的程序员,十分优秀!