Simplexml_load_file 空数组 [英] Simplexml_load_file empty array

查看:43
本文介绍了Simplexml_load_file 空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试加载此文档:

$url = "http://en.wikipedia.org/w/api.php?action=query&titles=Electrophoresis&prop=langlinks&lllimit=500";

当我在浏览器中运行它时,一切都很好.当我这样做时:

When I run it in browser, everything is fine. When I do this:

ini_set('user_agent', 'XX123456789 (localhost; myemailaddress)'); //sets info for authentication    
$content = file_get_content($url);
var_dump($content);

它返回与我的浏览器显示相同的 xml 文档.

It return the same xml document as my browser show.

但是当我尝试

$content_arrays = Simplexml_load_file($content);
echo '<pre>', print_r($content_arrays), '</pre>';

它返回一堆空数组.我就是不明白为什么.

It return a bunch of empty arrays. I just dont get why.

推荐答案

simplexml_load_file 返回一个对象,而不是一个数组.所以你不能只用print_r 打印它.您需要做更多的工作来浏览 SimpleXMLElement.

simplexml_load_file returns an object, not an array. So you can't just print it with print_r. You need to do more work to navigate through the SimpleXMLElement.

这篇关于Simplexml_load_file 空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆