This is a discussion on highlighting search terms results within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I've seen previous threads but I still need help in highlighting search terms like google does on their search ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I've seen previous threads but I still need help in highlighting
search terms like google does on their search result page. I know I need, ob_start(); Then I process to highlight the search term hits, then I flush the buffer to render the page. I'm comfortable with PHP coding but what I need is simple step by step help, with a simple search form example. The explanations I see are either way to lofty or too small a piece of the "puzzle". Thanks, Lee G. |
|
|||
|
If your target string is $str and your search terms are in the array $Terms:
<?php // create replacement HTML strings foreach ($Terms as $Term) { $Reps[] = "<B>" . $Term . "</B>"; } // perform replacements $strOut = str_ireplace($Terms, $Reps, $str); ?> Replace the <B></B> tags with whatever HTML highlighting you want. I can't see any reason why you'd specifically need to use output buffering with ob_start(). Hope this helps. Oli |
![]() |
| Thread Tools | |
| Display Modes | |
|
|