The goal would be: I have some titles. I would like to turn the titles in a text to link. BUT when it is a link, I DON'T want to change. I am looking for the right regex.
I have a PHP code like this:
foreach($res as $r) {
$new_string = '<a href="#" onclick="getMarkers(1,\\\' \\\',1);locate('.$r->latitude.','.$r->longitude.','.$r->zoom.','.$r->id.',0);">$0</a>';
$introduction = (preg_replace("/\b$r->title\b(?![^<>]*(?:<|$))/i",$new_string,$introduction))
}
This part of my code doesn't work:
preg_replace("/\b$r->title\b(?![^<>]*(?:<|$))/i",$new_string,$introduction)
The problem is: This regex also change the avilable links what is in HTML tag.
Thank you for everybody patiente and I am wainting for the answers!
Thanks!
UPDATE: I would like to say thank you for HamZa for this fantastic link!
My solutions is:
$introduction = (preg_replace("/[^>]*>.*?<\/a>(*SKIP)(*FAIL)|$r->title/im",$new_string,$introduction));
Thanks for everybody! :)