help with regular expressions: Warning: Unknown modifier
Posted: Mon Jul 17, 2006 1:36 pm
Hello,
The website I'm working on has a search function which displays the results with matches for the search term in bold. This effect is achieved with a simple snippet:
The problem is that sometimes the search term is part of a URL in an <a> tag, which makes for the following undesirable output:
After adding a little code to rectify this (to follow), I get the following PHP warning:
The idea was to highlight the search term only for records where the search term does not appear between <a> and </a>. This was supposed to be a quick fix; ideally, I'd like to be able to turn off the highlighting just for matches within the tags.
For example, I'd like the following to work:
The way I've written it (which doesn't even work), there would be no bolding at all.
Can anyone help with this? I especially need help with the unknown modifier warning; I might be able to figure out the rest on my own, though some help there would be appreciated as well.
Thanks,
The website I'm working on has a search function which displays the results with matches for the search term in bold. This effect is achieved with a simple snippet:
Code: Select all
$description = str_replace($q, "<strong>$q</strong>", $description);Code: Select all
<a href="http://www.<strong>searchterm</strong>.com/">some hyperlinked text</a>Here are lines 40 and 41 of the new code:Warning: Unknown modifier ']' in /food/bar/search3.php on line 41
Code: Select all
$needle = "<a[^>]*>.*(".preg_quote($q)."|".preg_quote($q_uc).").*</a>" ;
if(!preg_match($needle, $description)) { /*some stuff*/ }For example, I'd like the following to work:
Code: Select all
I like <strong>coffee</strong>. Visit <a href="http://www.coffee.com/">www.<strong>coffee</strong>.com</a>.Can anyone help with this? I especially need help with the unknown modifier warning; I might be able to figure out the rest on my own, though some help there would be appreciated as well.
Thanks,