eevan79 Posted April 6, 2011 Share Posted April 6, 2011 I have the auto suggestion script. While the user is typing, results are printed below (from the database). The results are printed with bold letters that are in the search. However, this leads to errors in capitalization. The letters are replaced by users' queries, instead of from the database. Example: Search word: PHP Results: PHPfreaks, PHP tutorials But in the database this is the records: "phpfreaks" and "php tutorials". This is a script that replaces search letters with bolded: $search = clean($_POST["search"]); $fname=$row['name']; //Record from database $re_fname='<b>'.$search.'</b>'; //Replace with bold letter $final_fname = str_ireplace($search, $re_fname, $fname); How to do a script that bold letters, but as they were in the database, not from search input? Quote Link to comment Share on other sites More sharing options...
kireoke Posted April 6, 2011 Share Posted April 6, 2011 You'll need to remember the match, which unfortunately involves preg_match(): $search = clean($_POST["search"]); $junk = preg_match('/'.$search.'/i',$fname,$matches); $whatyouwant = $matches[0]; $re_fname='<b>'.$whatyouwant.'</b>'; //Replace with bold letter $final_fname = str_ireplace($search, $re_fname, $fname); ..that may be too much overhead. I'd have to think about it harder, but that should work. What auto suggestion script are you using? I need a good one. Quote Link to comment Share on other sites More sharing options...
kireoke Posted April 6, 2011 Share Posted April 6, 2011 Sorry, forgot the $fname=$row['name'] if that wasn't obvious. Quote Link to comment Share on other sites More sharing options...
eevan79 Posted April 6, 2011 Author Share Posted April 6, 2011 What auto suggestion script are you using? I need a good one. I am using this script: http://demos.9lessons.info/auto.htm But I revised it for my needs. I tried your solution and works ok. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.