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

Rod*_*the 6 php xml xml-parsing

我很难过如何使用我的PHP解析脚本从这个XML位的"link"标签中提取"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>
Run Code Online (Sandbox Code Playgroud)

这是我的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 = ???;
}
Run Code Online (Sandbox Code Playgroud)

有关如何提取"href"属性的任何建议?

谢谢!

jwu*_*ler 7

怎么样DOMElement::getAttribute

$href = $node->getElementsByTagName('link')->item(0)->getAttribute('href');
Run Code Online (Sandbox Code Playgroud)