gpt4 book ai didi

php - 如何使用 PHP 从 XML "href"标记中提取 "link"属性?

转载 作者:可可西里 更新时间:2023-11-01 13:20:14 25 4
gpt4 key购买 nike

我对如何使用我的 PHP 解析脚本从这段 XML 的“链接”标记中提取“href”属性感到困惑。如果有帮助,我正在尝试从 GetSatisfaction API 提要中提取特定帖子的 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”属性有什么建议吗?

谢谢!

最佳答案

DOMElement::getAttribute呢? ?

$href = $node->getElementsByTagName('link')->item(0)->getAttribute('href');

关于php - 如何使用 PHP 从 XML "href"标记中提取 "link"属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4379699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com