Forum Moderators: coopster
I have code that highlights keywords matching in search results, but there are 2 problems:
1. It is case sensitive- I want to make it insensitive.
2. It will match and highlight other elements I don't want- such as headings/titles, and will mess up the code links. It would be great to limit the highlighting to a certain variable $row['vtext'] and nothing else.
I have read several related posts on this, but nothing I've seen quite works. Here's the current code:
if(!isset($word)) { $word = $_POST['word']; }
function callback($buffer) {
global $word;
return (ereg_replace($word, "<span class='highlight'>$word</span>", $buffer));
}
ob_start("callback");
// echo statements for results
ob_end_flush();
Any ideas? Thanks!
Here's what I have for the first part of my code:
$word=$HTTP_GET_VARS ['word'] ;
then this:
if(!isset($word)) { $word = $_POST['word']; }
function callback($buffer) {
global $word;
return (ereg_replace($word, "<span class='highlight'>$word</span>", $buffer));
}
ob_start("callback");
// echo statements for results
ob_end_flush();
I tried substituting this code in every possible combination I could think of, but either gave an error or behaved the same.
strtolower($word) == strtolower($_POST['word']);
any ideas?
You might want to look at the case insensitive eregi_replace [php.net] to replace the ereg_replace function you have used in your code.