PHP preg_replace help

Advert test

Tom

New Member
#1
I need to parse a string using php preg_replace. I need it to find instances of src=" then change it to src="http://www.mysite.ie/ but only if it's not already src="http://www.mysite.ie/

so it would change the following

Code:
<img src="http://www.irishwebmasterforum.com/images/0.png">
<img src="http://www.mysite.ie/images/0.png">
<img src="http://www.irishwebmasterforum.com/images/0.png">
to

Code:
<img src="http://www.mysite.ie/images/0.png">
<img src="http://www.mysite.ie/images/0.png">
<img src="http://www.mysite.ie/images/0.png">
Does anyone know how to do this? I hate regular expresions.


Edit: Ok I'm getting somewhere now using the pattern below, this might do the trick..

Code:
(?!src="http)src="
 
#2
PHP:
<?php

    $source = '<img src="http://www.irishwebmasterforum.com/images/0.png">
<img src="http://www.mysite.ie/images/0.png">
<img src="http://www.irishwebmasterforum.com/images/0.png">';

    $data = preg_replace('#<img src="http://[a-z.]+/images/0.png">#iSu', '<img src="http://www.mysite.ie/images/0.png">', $source);
    
    echo $data;

?>
 
Top