如何提取“href”来自 XML“链接”的属性使用 PHP 标记?
我很困惑如何使用我的 PHP 解析脚本从这段 XML 的“link”标记中提取“href”属性。如果有帮助的话,我正在尝试从 GetSatisfaction API feed 中提取特定帖子的 URL。
下面是 XML 文件中的一个节点示例:
<entry>
<link rel="something" href="http://...url_I_need" type="text/html"/>
<title type="html">...title here...</title>
<content type="html">
...content here...
</content>
</entry>
这是我的 PHP XML 解析脚本的数据收集部分:
$doc = new DOMDocument();
$doc->load('http://api.getsatisfaction.com/companies/issuetrak/topics?sort=recently_active&limit=7');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('entry') as $node) {
$title = $node->getElementsByTagName('title')->item(0)->nodeValue;
//I need to just store the link->href value to $link below
//$link = ???;
}
关于如何提取“href”属性有什么建议吗?
谢谢!
I am stumped as to how I can extract the "href" attribute from the "link" tag from this bit of XML using my PHP parsing script. If it helps at all, I am trying to extract the URL of a particular post from a GetSatisfaction API feed.
Here is an example a node from the XML file:
<entry>
<link rel="something" href="http://...url_I_need" type="text/html"/>
<title type="html">...title here...</title>
<content type="html">
...content here...
</content>
</entry>
And here is the data gathering portion of my PHP XML parsing script:
$doc = new DOMDocument();
$doc->load('http://api.getsatisfaction.com/companies/issuetrak/topics?sort=recently_active&limit=7');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('entry') as $node) {
$title = $node->getElementsByTagName('title')->item(0)->nodeValue;
//I need to just store the link->href value to $link below
//$link = ???;
}
Any suggestions on how to extract that "href" attribute?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DOMElement::getAttribute
怎么样?What about
DOMElement::getAttribute
?我认为你可以使用:
但我更喜欢使用 simpleXml;
http://www.php.net/simpleXml
I think that you can use:
But I prefere use simpleXml;
http://www.php.net/simpleXml