Jump to content

eregi_replace help


me1000

Recommended Posts

ok here is what i have so far...

im trying to add a feature to my search page that will highlight the searched words

sorry for the messy code, it is scattered throughout the page, I just got all the important stuff.
i left out a lot of the code, including the loop for diplaying the results. so say you search for the word, dog
then what you see here will replace the word doggy with 'gy' removing the 'dog' part of it all together. hope you can tell me whats wrong with it,

Thanks,

[code]
$inKeyword = preg_match("/^[A-Za-z]([A-Za-z0-9\s]*[A-Za-z0-9])*$/",$_POST['search']) ? $_POST['search'] : die("Bad Search Term Numbers and Letters only");
$result = mysql_query("SELECT * FROM $sTableName WHERE PAGE_CONTENT LIKE '%$inKeyword%'");

$text_output = strip_tags($message, '');
   $search_results = substr($text_output, 0, 200);
  
//begin highlighting searched word
   $searchterm = array($inKeyword);

foreach($searchterm as $searchwords) {

$search_results = eregi_replace($searchwords, "<span style=\"background-color: yellow;\"$searchwords </span>", $search_results);

}
//end highlight search word

   //display the search results

echo "$link <br> $search_results ... <br><hr>";
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.