Page 1 of 1

str_replace

Posted: Fri Oct 24, 2003 3:15 pm
by d3ad1ysp0rk
I'm sorry, but I read both the php.net and Zend articles and comments on str_replace, but I just can't seem to understand it..

can anyone explain what goes into the parenthesis?

ie, mail() is mail(who its to, the message, the headers)

what would str_replace() be?


ThanKs

Posted: Fri Oct 24, 2003 3:49 pm
by Cruzado_Mainfrm
str_replace("what you look for","the substring that is going to replace 'what you look for'",$TheStringThatContainsEverything);

ie.:

Code: Select all

<?php
$greeting = "Hi my name is John";

str_replace("Earl","John",$greeting);

echo $greeting; //will return: Hi my name is Earl

?>
good luck

Posted: Fri Oct 24, 2003 4:01 pm
by d3ad1ysp0rk
k thanks a lot :D

Posted: Fri Oct 24, 2003 4:08 pm
by d3ad1ysp0rk
What about replacing 's?

I have a variable called $varsign and I want to get rid of all the 's and change them to ' (the HTML number for them) so i dont get this:

"John's cat is very fast."
becomes
"John''s cat is very fast."

yet it seems to not replace it..

my code:

Code: Select all

str_replace("'","'",$varsign);
Thanks

Posted: Fri Oct 24, 2003 5:04 pm
by markl999
str_replace returns the new string with the replacements. So you have to assign it to something, usually the original string.

Code: Select all

$varsign = str_replace("'", ''', $varsign);

Posted: Mon Oct 27, 2003 3:02 am
by twigletmac
You don't need str_replace() to get rid of escape characters (the backslashes), use stripslashes() instead, or turn off magic_quotes in your php.ini.

Mac