tags:

views:

93

answers:

1

I'm using php to process rss data, however often feeds have more than image in the description. Can someone help me out with some regex or something to remove all but the first image in the feed? I'd only like to have a max of one image.

Assuming the feed description in is in a variable such as "Sdescription".

CLARIFICATIONS: I've used an xml parser, the string for the description tag just has multiple images, all I need to know is how to remove all images from a string except the first one.

+1  A: 

I don't think a regex is necessarily what you want. I'd parse the feed with one of PHP's XML readers and just pull out what you want - the first image.

Check out SimpleXML it should get you started.

Jason McCreary