mikefrederick Posted February 13, 2008 Share Posted February 13, 2008 why does this not work? it replaces each $x in the array with the actual word array rather than the original word. $bar = $_GET['letters']; $x=explode(" ",$bar); $a=str_replace($x,"<span style='color: #000066; font-weight: 600'>" . $x . "</span>",$t); Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 13, 2008 Share Posted February 13, 2008 because you need to use str_replace on a string variable in your case $x is an arrary Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted February 13, 2008 Author Share Posted February 13, 2008 how do I do this then? I mean you can use an array for the value you want to replace, why not for the value you are replacing it with Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 13, 2008 Share Posted February 13, 2008 because $x is an array try this: $a=preg_replace("/\$x/,"<span style='color: #000066; font-weight: 600'>$1</span>",$t); Update: scratch the above...posting another one is sec Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted February 13, 2008 Share Posted February 13, 2008 PHP replacement type functions or search functions work on a principle of needle in a haystack meaning your needle (must be integers or string mostly) is searched for in a haystack (most var types integers, string, arrays) You must do a foreach and replace each node of $x individually or some alternative method Edit: if that isn't clear your needle is your original string, and the haystack is your query pool what is to be found. I think I stated it backwards:) Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 13, 2008 Share Posted February 13, 2008 <?php foreach(explode(" ",$bar) as $x) $t = str_replace($x,"<span style='color: #000066; font-weight: 600'>{$x}</span>",$t); ?> Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted February 13, 2008 Author Share Posted February 13, 2008 thanks rhodesa 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.