php regexp for get images [duplicate]
Possible Duplicate:
Regex to change format of all img src attributes
Hi,
I want to replace the image path in my content db field.
I have the following
开发者_JS百科preg_replace("/src='(?:[^'\/]*\/)*([^']+)'/g","src='newPath/$2'",$content);
which is working fine for
src="/path/path/image.jpg"
BUT fails ON
src="http://www.mydomain.com/path/path/image.jpg"
Any help to bypass this problem?
Don't use regular expressions for this. Use a HTML parser like Simple HTML DOM.
$html = file_get_html('http://www.example.com/sourcepage.html');
foreach($html->find('img') as $element)
{
$new_src = "Do stuff with new src here";
$element->src = $new_src;
}
echo $html; // Output new code
精彩评论