Jump to content

srt_replace problem


AbydosGater

Recommended Posts

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

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

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

<?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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.