简单的 XML PHP 错误 - Echo 没什么
好吧,
基本上,我从这样的 URL 加载 simplexml_load_file ,
$stats = simplexml_load_file("http://example.com/api/api.asmx/Campaign.GetSummary?ApiKey=$apikey&CampaignID=$CID");
它返回这个
SimpleXMLElement Object
(
[Recipients] => 1
[TotalOpened] => 0
[Clicks] => 0
[Unsubscribed] => 0
[Bounced] => 0
[UniqueOpened] => 0
)
在我加载之后我想回显信息,所以我尝试像这样回显它
echo '<ul id="views">';
echo '<li>';
print $stats['Recipients'];
echo '</li>';
echo '</ul>';
但是当它运行时,我没有得到任何数据,只是一个空的
Ok guys,
Essentially, im loading a simplexml_load_file from a URL like this
$stats = simplexml_load_file("http://example.com/api/api.asmx/Campaign.GetSummary?ApiKey=$apikey&CampaignID=$CID");
Which returns this
SimpleXMLElement Object
(
[Recipients] => 1
[TotalOpened] => 0
[Clicks] => 0
[Unsubscribed] => 0
[Bounced] => 0
[UniqueOpened] => 0
)
After I load that up I want to echo the info, so I try to echo it out like so
echo '<ul id="views">';
echo '<li>';
print $stats['Recipients'];
echo '</li>';
echo '</ul>';
But when it runs, I dont get any of the data, just an empty <li></li>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 SimpleXMLElements 时,不使用
[]
表示法 - 而是使用->
。因此,您的代码应该是:我相信这种表示法可能(在我的应用程序中确实如此,但我对 SimpleXMLElements 不太熟悉)返回 SimpleXMLElement 对象,而不是字符串 - 您可以将其转换为字符串/整数/任何在比较等中使用它的东西。
When working with SimpleXMLElements, you do not use the
[]
notation - instead you use->
. So, your code should be:I believe such notation may (it does in my application, but I am not overly familiar with SimpleXMLElements) return a SimpleXMLElement object, not a string - you can cast it to a string/int/whatever to use it in comparisons etc.
SimpleXMLElement Object
不是一个数组,它是一个对象,线索就在名称中:-)您需要使用对象表示法来访问它
SimpleXMLElement Object
is not an array, it is an Object, the clue is in the name :-)You need to access it using Object notation