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). Link to comment https://forums.phpfreaks.com/topic/90937-agh-help-strings/ 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. Link to comment https://forums.phpfreaks.com/topic/90937-agh-help-strings/#findComment-466083 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); ?> Link to comment https://forums.phpfreaks.com/topic/90937-agh-help-strings/#findComment-466106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.