Quantcast
Channel: Get img url from enclosure in rss feed - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by SunMar for Get img url from enclosure in rss feed

$
0
0

Try looking at http://php.net/manual/en/domelement.getattribute.php to see how to fetch an attribute from a DOMElement. In this case you could use $node->getElementsByTagName('enclosure')->item(0)->getAttribute('url') to get the image URL. You could also try using SimpleXMLElement (see PHP documentation) which is a bit easier to use than DOMDocument (but as a trade-off also has less functionality).

Some other pointers, if you are only appending one element to an array, instead of using array_push use the syntax $array[] = $element. $array[] is a language construct which is more efficient than an internal function like array_push. Also instead of using str_replace to replace & with &amp;, use htmlspecialchars or htmlentities, it's safer and also replaces other characters that you don't want in your HTML like < and >.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>