Author Topic: highlighting search terms  (Read 13537 times)

0 Members and 1 Guest are viewing this topic.

Offline lwc

  • Irregular
  • Posts: 35
    • View Profile
Re: highlighting search terms
« Reply #15 on: July 28, 2008, 07:32:40 PM »
Of course, your code only works in sites with strictly Latin words. Otherwise, see this.

Offline ddrudik

  • Enthusiast
  • Posts: 78
    • View Profile
    • myregextester.com
Re: highlighting search terms
« Reply #16 on: October 28, 2008, 10:43:03 PM »
I would suggest:
search_term(?!(?=[^<>]*>))

Offline ddrudik

  • Enthusiast
  • Posts: 78
    • View Profile
    • myregextester.com
Re: highlighting search terms
« Reply #17 on: October 30, 2008, 04:43:26 AM »
Also, if you want to exclude search_term from within head/script/a blocks as well as from within tags:
Code: [Select]
$html=preg_replace_callback('~(<head>.*?</head>|<script\s[^>]*>.*?</script>|<a\s[^>]*>.*?</a>)|search_term(?!(?=[^<>]*>))~is',create_function('$matches','return isset($matches[1]) ? $matches[1] : "<strong>$matches[0]</strong>" ;'),$html);


Offline lwc

  • Irregular
  • Posts: 35
    • View Profile
Re: highlighting search terms
« Reply #18 on: December 16, 2008, 02:16:49 PM »
I do like this...
I like this too. But can you deal with "&lt;" and "&gt;" too?