php - preg_match string not within the href attribute

cecilberlin

New Member
i find regex kinda confusing so i got stuck with this problem:i need to insert \[code\]<b>\[/code\] tags on certain keywords in a given text. problem is that if the keyword is within the href attribute, it would result to a broken link.the code goes like this:\[code\]$text = preg_replace('/(\b'.$keyword.'\b)/i','<b>\1</b>',$text);\[/code\]so for cases like\[code\]this <a href="http://stackoverflow.com/questions/3733762/keyword.php">keyword</a> here\[/code\]i end up with:\[code\]this <a href="http://stackoverflow.com/questions/3733762/<b>keyword</b>.php"><b>keyword</b></a> here\[/code\]i tried all sorts of combinations but i still couldn't get the right pattern.thanks!
 
Back
Top