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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.