mikefrederick Posted February 13, 2008 Share Posted February 13, 2008 Okay, have a script I am using to search a database. It searches correctly, separating each worth with a space (" "). However, I am also trying to replace the search query with a different color, and this only works up until the first space. After that, the search still works but nothing is replaced with a different color. Thanks in advance: $bar = $_GET['letters']; $bar = preg_replace("/[^a-z0-9 ]/si","",$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"]; $a=str_replace($bar,$z,$t); echo $inf["id"]."###".$a."|"; } $a=str_replace($bar,$z,$t); is the function used to replace the search query (I realize how incorrect I have this setup right now, I just held down apple+z for about a half hour undoing the different ways I have tried this). Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted February 13, 2008 Author Share Posted February 13, 2008 someones gotta know. my problem is that I need to do str_replace to each part of the exploded array, and replace it with the same thing in a different color. but when I try to do that, it actually replaces each word with the word array. Quote Link to comment Share on other sites More sharing options...
sasa Posted February 13, 2008 Share Posted February 13, 2008 try <?php $x = array('add','xx','yy'); $t = 'Add fg hij yy maxxim'; echo $o = preg_replace('/(('.implode(')|(',$x).'))/i','<span style=\'color: #000066; font-weight: 600\'>$1</span>',$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.