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? Link to comment https://forums.phpfreaks.com/topic/40380-srt_replace-problem/ 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 Link to comment https://forums.phpfreaks.com/topic/40380-srt_replace-problem/#findComment-195380 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.. Link to comment https://forums.phpfreaks.com/topic/40380-srt_replace-problem/#findComment-195392 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 />"; ?> Link to comment https://forums.phpfreaks.com/topic/40380-srt_replace-problem/#findComment-195401 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 Link to comment https://forums.phpfreaks.com/topic/40380-srt_replace-problem/#findComment-195411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.