Jump to content


Photo

eregi_replace help


  • Please log in to reply
1 reply to this topic

#1 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 04 April 2006 - 11:58 PM

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.
here is the problem...
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,

$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>";


#2 stephenk

stephenk
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 08 April 2006 - 09:12 PM

I didnt examine all your code, but theres an error in the eregi_replace. Try:

"<span style=\"background-color: yellow;\>".$searchwords ."</span>";

Stephen




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users