我正在尝试使用simplexml来读取feedburner xml。我可以读取xml中的所有属性,但不能读取带有“:”的键。示例"feedburner:origLink“。当我给这些项赋值时,那些带有:的键不会出现。我不能像$s->item->feedburner:origLink那样做。
发布于 2010-08-21 21:31:19
您正在处理名称空间,而this Sitepoint article看起来像是一个很好的长篇解释。或者更简明的版本,请查看here in the PHP SimpleXML docs。
从文档中:
<?php
$xml = '<example xmlns:foo="my.foo.urn">
<foo:a>Apple</foo:a>
<foo:b>Banana</foo:b>
<c>Cherry</c>
</example>';
$sxe = new SimpleXMLElement($xml);
$kids = $sxe->children('foo');
var_dump(count($kids));
$kids = $sxe->children('foo', TRUE);
var_dump(count($kids));
$kids = $sxe->children('my.foo.urn');
var_dump(count($kids));
$kids = $sxe->children('my.foo.urn', TRUE);
var_dump(count($kids));
$kids = $sxe->children();
var_dump(count($kids));
?>输出:
int(0)
int(2)
int(2)
int(0)
int(1)发布于 2015-10-28 04:54:11
如果你很懒,不介意使用google webservices,这里有一个简单的方法可以将feed google(或其他)提要的全部内容放到php中:
http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=100&q=http://feeds.feedburner.com/variety/headlines
然后你可以简单地json_decode它,它就在你的对象/数组中了。
https://stackoverflow.com/questions/3537655
复制相似问题