I am trying to use preg_replace to add rel="nofollow" to a link and am having a difficult time with it due to my regexp abilities. The way I am currently doing it is i read the string into a variable and then explode with <a href=. I then compare each array element for whether or not it contains my domain and if it does not then i do the preg replace. I am sure there is an easier way of doing it, but I do not know how. Can i just use a regexp in preg_replace to conver the string if and only if the domain portion does not match a certain string?
Here is my code which does not work:
$search = array ('/"(\S+)"(.+)</a>/' );
$replace = array ('"$1" rel="nofollow" $2</a>');
$done[$count] = preg_replace($search,$replace,$value);
I am using an array as after I get this to work I will be doing more substitutions.
Any suggestions as to why this does not work?