Hi,
I was making a search box and was trying to highlight the words that the users will enter in the search box,for example if the user enter "kids" in the searchbox it should highlight the "kids" word in the result............. is anyone have an idea how to do that
micahgeorge 0 Newbie Poster
Recommended Answers
Jump to PostYou will need some sort of regular expression to find the matching word.
E.g:$i=0; while (there are results) { if(preg_match("/the search term/i", $results[$i], $yellow)) { echo "<span id = "yellow">" $yellow[$i] . $results[$i] ."</span><br>"; } }
Not exactly... but you can follow the logic x
Jump to Postgo through this
<? ob_start(); extract($_REQUEST); extract($_POST); $searchtext=$_REQUEST['searchtext'];/////////////$_REQUEST['searchtext'] your search content if($searchtext=='') { $exists=1; } function search_highlight($needle, $replace, $haystack) { $haystack = eregi_replace($needle,$replace,$haystack); return $haystack; } //echo $searchtext;exit; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
All 5 Replies
nonshatter 26 Posting Whiz

james.newell

james.newell
micahgeorge 0 Newbie Poster
muralibobby2015 17 Posting Pro
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.