AbydosGater Posted February 27, 2007 Share Posted February 27, 2007 Hey guys, Ok im trying to make it so my script accepts a string from GET and takes all the quotes and replaces them with the word "Quote".. I came up with.. <?php $abw["""] = "Quote"; $string = $_GET['str']; $letters = str_split($string); foreach ($letters as $num => $letter){ str_replace(""", $abw["\""], $letter); echo $letter; } ?> But when i run it, it is replacing the quote with \" instead of Quote? I dont think i have the srt_replace backwards according to the manual! Anyone see whats happening? Quote Link to comment Share on other sites More sharing options...
Stooney Posted February 27, 2007 Share Posted February 27, 2007 heres is a bit from php.net/str_replace // Provides: You should eat pizza, beer, and ice cream every day $phrase = "You should eat fruits, vegetables, and fiber every day."; $healthy = array("fruits", "vegetables", "fiber"); $yummy = array("pizza", "beer", "ice cream"); $newphrase = str_replace($healthy, $yummy, $phrase); looks like you had it backwards a bit Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted February 27, 2007 Author Share Posted February 27, 2007 No i have it right: $abw["""] = "Quote"; $string = $_GET['str']; $letters = str_split($string); foreach ($letters as $num => $letter){ str_replace(""", $abw["""], $letter); echo $letter; } Im looking for " in $letter and replacing it with $abw["""].. Which is what that should do.. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 27, 2007 Share Posted February 27, 2007 <?php $replaces = Array(); $replaces["\""] = "Quote"; $replaces["""] = "Quote"; $str = "Hello, "World!\""; echo $str . "<br />"; foreach($replaces as $find => $replace){ $str = str_replace($find, $replace, $str); } echo $str . "<br />"; ?> Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted February 27, 2007 Author Share Posted February 27, 2007 Yeah Thanks, But whats the difference between that and this, <?php $abw = array(); $abw["""] = "Quote"; $string = $_GET['str']; $letters = str_split($string); foreach ($letters as $num => $letter){ str_replace(""", $abw["""], $letter); echo $letter; } ?> Cause thats still returning \" and i need it to loop through each letter and replace not the entire string! Andy 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.