hi, I use Preg_replace to automatically links some keywords Here is my code $texte = preg_replace('`\b((keyword)s?)\b`si','<a href="../keyword.html">$1</a>',$texte); Code (markup): It workes great but when my keyword is inside an element like <a href="zzz"> </a> it breaks the links. My questions is how can i do that preg_replace will note replace any keywords inside an element? And a second question how can i do that preg_replace dosen't match when there is an - directly before my keyword? I hope that you all understand my english Thanks for your help
Modify this as needed. $String="<a href='blah.com'>welcome to blah</a>"; $msgStrip = preg_replace('/<a\s+.*?[href=]["|\']([^"\']+)["|\']> {1}([^<]+)<\/a>/is', '\2 (\1)',$String); it will output welcome to blah (blah.com) Code (markup): If you like what I have posted feel free to drop me some reputation =) Hope this helps and Happy New year
preg_replace ('`[^"\'](keywords?)[^"\']`si', '<a href="../keyword.html">$1</a>'); This looks for quotes (single or double) before and after the keyword(s) and does not match if there are. preg_replace ('`[^-](keywords?)`si', '<a href="../keyword.html">$1</a>');