[英]How do I extract the “href” attribute from an XML “link” tag using PHP?
我很難過如何使用我的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>
這是我的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”屬性的任何建議?
謝謝!
$href = $node->getElementsByTagName('link')->item(0)->getAttribute('href');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.