How do I extract the "href" attribute from an XML "link" tag using PHP?
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&lim开发者_Go百科it=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!
What about DOMElement::getAttribute
?
$href = $node->getElementsByTagName('link')->item(0)->getAttribute('href');
I think that you can use:
$link = $node->attributes['href'];
But I prefere use simpleXml;
http://www.php.net/simpleXml
精彩评论