I've got a little problem as my preg_match_all isn't running correctly.

what I wish to do is extract the src parameter of all of the images within the publish_content in the wordpress the industry string - not really a complete html document/DOM (thus cannot make use of a document parser function)

I'm presently while using below code that is regrettably too untidy and works best for only one image src, where I would like all image sources from that string

preg_match_all( '/src="([^"]*)"/', $search->post_content, $matches);

if ( isset( $matches ) )

foreach ($matches as $match) 

if(strpos($match[0], "src")!==false)
$res = explode("\"", $match[0]);
echo $res[1];



can someone help here...

Use a DOM parser with HTML strings, there is no need to possess a complete HTML document. http://simplehtmldom.sourceforge.net/

Using regular expressions to parse an HTML document can be quite error prone. As with your situation where not just IMG elements come with an [cde] attribute (actually, that does not even have to be an HTML attribute whatsoever). On top of that, additionally, it may be entirely possible that the attribute value isn't enclosed in double quote.

Better make use of a HTML DOM parser like PHP’s DOMDocument and it is techniques: