|
Posted by Jim on 10/29/07 21:05
I just spotted one error, the equals sign after the negative
lookbehind, although that seems to have made little difference.
Updated code follows:
<?php
$prefix = 'http://mydomain.com/';
$content = <<<EOT
<img src="images/test.gif" alt="Test Image" />
<img src="http://shouldnt.be.changed/images/test.gif" alt="Test
Image" />
EOT;
echo preg_replace('/\<img(.+?)src="(?<!http)(.+?)"(.+?)\/>/', '<img
$1src="' . $prefix . '$2"$3/>', $content);
/*
* First img element's src attribute should be
* changed, but not the second's.
*/
?>
Navigation:
[Reply to this message]
|