I am trying to get the first image of each feed post. An image always exists inside each <description> , as shown below.
<description><p><a href="http://lh5.ggpht.com/-kDNySEwupXc/Tesp_XbEXQI/AAAAAAAAKZY/t5TMtq7SkCs/s1600-h/image%25255B4%25255D.png">< ....></description>
I get the title, author and other content below
foreach ($entries as $entry) { echo "<pre>"; echo $entry->title; echo" -- "; echo $entry->author; echo" -- "; echo $entry->pubDate; echo"<br>"; echo "</pre>"; }
but I donβt know if the image is an attribute inside the description. If so, how can I show it? I think this solution is much simpler and faster than using a regular expression like this to get the first image:
preg_match('!http://.+\.(?:jpe?g|png|gif)!Ui'
If regex is the only solution, how can I use it?
thanks
source share