So I want to replace "strings" for <a>"strings"</a> having an array with strings and another one with URLs. Everything worked like a charm at first, it replaces the first coincidence not withint tags > < ,but when I started populating the array with strings and urls I found out that if it replaces "Fantasy games" -> <a href="ASDFASDF">Fantasy games</a> and then it has to replace "Fantasy" it simply skips the >string< check of the regex and goes ahead and replaces it anyway, breaking the html code and creating parse errors.
So I'm presuming I'm doing something wrong or missing a parameter or something because if the content has >string< it doesn't replace it but if I do it with the preg_replace then is like if I've done it wrongly because it doesn't detect it like >string< when it's going to replace the next element of the array.
Here is the code:
// DB content
// $Keywords=array("Fantasy games", "Fantasy");
// $URL=array("http://www.whatever.com", "http://www.whatever2.com");
$i=0;
// Insert the links and returns the processed content.
foreach ($SQLResult as $row){
    $Keywords[$i]="/[^>](".$row->Keyword.")[^<]/i";
    $URLS[$i]=' <a href="'.$row->URL.'">$1</a> ';
    $i++;
}   
$Content=preg_replace($Keywords, $URLS, $Content, 1);
 
     
     
    