Im using preg_replace to replace keywords in text with a href tag, my regex is working awesome, right now my code is:
$newstring2 = preg_replace("/\p{L}*?".preg_quote($match[$i])."\p{L}*/ui", "<a href='".$url."' class='link'>$0</a>", $newstring);
Only problem with this is, that I need to exclude any keywords inside <a href='https://keyword.cz' title="keyword">keyword</a>
This is what I found https://stackoverflow.com/a/22821650/4928816
So is here someone who can help me merge this two regex together?
Example:
$text = 'this is sample text about something what is text.'
$keyword = 'text'
Now thanks to my regex I get:
$text= 'this is sample <a href='somelink.php'>text</a> about something what is <a href='somelink.php'>text</a>.'
But If text is :
$text= 'this is sample <a href='text.php'>text</a> about something what is <a href='somelink.php'>text</a>.'
This is what for example I get:
$text= 'this is sample <a href='<a href='somelink.php'>text.php</a>'><a href='somelink.php'>text</a></a> about something what is <a href='somelink.php'><a href='somelink.php'>text</a></a>.'
Update: Why do I need this. Working on function to replace all keywords with specific URL in specific blog post full of tags.. For examle if
$keyword = 'key';
I need to find and replace full world with a href tag, for example: Key, Keyword, keyword, keylock, mykey, keys or also KeY, Keyword with UNICODE support