Get first image from html

You must Login before you can answer or comment on any questions.

Hey guys,

I would like to grab the url (the src) of the first img tag found in a chunk of html. The html is taken from a description tag from an rss 2 feed I've parsed, and I've love to grab the first image inside it to use as a thumbnail.

Now, the usual javascript way, ala w3schools is not working for me. I've had a look at Kitchen Sink's strip_tags.js, but nothing really fits...

Probably really simple, but it's been a long night on this. Any ideas, please?

1 Answer

Accepted Answer

<img[^>]+src=\"([^\"]+)\"
<- regex is your friend, throw that against your the contents of your description tag (assumes double quotes)

Your Answer

Think you can help? Login to answer this question!