mikefrederick Posted February 14, 2008 Share Posted February 14, 2008 Check out scripts.loado.com/friendsearcher.php. Type in University Wisconsin Madison (slow enough to let the search results populate while typing - slow server). After you type a space and then M for Madison, Wisconsin typically becomes unhighlighted. The search box works, but not correctly all of the time. What you are searching for should be highlighted in the search results that show up, but sometimes words do not get highlighted until the entire word has been searched for, and sometimes they do not get highlighted at all, and sometimes they become unhighlighted as I just said above. I think it words better in Safari than Firefox. How should I improve this script to get rid of these annoying errors? $bar = $_GET['letters']; $bar = preg_replace("/[^a-z0-9 ]/si","",$bar); $x=explode(" ",$bar); $u=explode(" ",$bar); $e=array($u); $z="<span style='color: #000066; font-weight: 600'>" . implode(" </span><span style='color: #000066; font-weight: 600'>",$x) . "</span>"; $search = "WHERE name LIKE '%" . implode("%' and name LIKE '%", $x) . "%' "; $res=mysql_query("select * from schools " . $search . " order by name limit 7"); while($inf = mysql_fetch_array($res)){ $t=$inf["name"]; foreach($u as $x) $t= str_replace($x,"<span style='color: #000066; font-weight: 600'>" . $x . "</span>",$t); echo $inf["id"]."###".$t."|"; } Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted February 14, 2008 Author Share Posted February 14, 2008 It actually turns out that what was not only slowing the script down a lot but causing those errors was the preg_replace...why? What did I do wrong? Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted February 14, 2008 Author Share Posted February 14, 2008 Actually that wasn't the only problem, just fixed some of the errors, some words still aren't being highlighted correctly. Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted February 14, 2008 Author Share Posted February 14, 2008 anyone? Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted February 14, 2008 Author Share Posted February 14, 2008 here is the code I am using now, a little better but still not much, and in addition, sometimes the <span> will show up in the search box. example: type in "University Wisconsin Madison t". whyy if(isset($_GET['getCountriesByLetters']) && isset($_GET['letters'])){ $bar = $_GET['letters']; $replace[0]="-"; $replace[1]="the "; $replaces[1]=""; $replaces[0]=""; $bar=str_replace($replace,$replaces,$bar); $replacee[0]=" of "; $replacee[1]=" in "; $replacesz[1]=" "; $replacess[0]=" "; $bar=str_replace($replacee,$replacess,$bar); $x=explode(" ",$bar); $z="<span style='color: #000066; font-weight: 600'>" . implode(" </span><span style='color: #000066; font-weight: 600'>",$x) . "</span>"; $search = "WHERE name LIKE '%" . implode("%' and name LIKE '%", $x) . "%' "; $res=mysql_query("select * from schools " . $search . " order by name limit 7"); while($inf = mysql_fetch_array($res)){ $t=$inf["name"]; foreach(explode(" ",$bar) as $x) $t= str_replace($x,"<span style='color:#000066'>" . $x . "</span>",$t); echo $inf["id"]."###".$t."|"; } 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.