Extracting String

This is small but very useful script.

I have shown example for extracting only ‘src’ value from the ‘img’ tag, but you can modify and use as per your requirement using ‘preg_match_all’ function.


$src= '<img height="120" width="120" border="0" src="http://www.somesite.com/abc.jpg" class="image"/>';

preg_match_all('/(src)=("[^"]*")/i',$src, $matches);	
echo str_replace('"','',$matches[2][0]);	

Output will be ‘http://www.somesite.com/abc.jpg’

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top