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

标签 php xml xml-parsing

我对如何使用我的 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/

相关文章:

php - 使用 MYSQL 的 UTF-8 插入查询在部署服务器上不工作

java - 在 Android 上使用 "Simple"XML 序列化从 res/raw 加载数据

python - XML 解析 : Element Tree (etree) vs. minidom

java - 坚持使用 JDOM 解析?

python - 如何在python中搜索具有给定属性值的Xml节点

javascript - Internet Explorer/MS Edge 浏览器问题遍历 xml 数据

javascript - sceditor:如何将数据保存到 mysql 或从中加载数据

php - 如何修复不断进行的重定向过程?

php - 对 watch 。健康)状况

java - JAXB 将多个对象编码到一个文件