Re: [PHP] str_replace oddity



Kevin Waterson wrote:
I am using str_replace to strip double quotes.

$string = 'This string has "quotes" in it';

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

this seems to work, yet when I put the $string into mysql,
it uses backslashes to escape where the quotes were. The
double-quotes are gone, yet it still escapes the 'ghost'
where they were.

I even tried str_replace(array("\x8c", "\x9c", "'", '"'), '', $string)
but the ghost remains and mysql continues to escape them.

I check the charsets, and the db is Latin-1 and the sting is ISO-8859-1

Any thoughts on this would be most graciously accepted.
Kind regards
kevin


is $string honestly something that you are getting via a form submit?

if so, your system might have magic quotes enabled.

This would automatically escape quotes with the attempt to make the values safer, and then you go and run your str_replace command and remove the double quotes, you end up leaving the '\' that the system automatically put in the value for you.

read up on magic quote gpc

hope this helps.

Jim

--
Jim Lucas


"Perseverance is not a long race;
it is many short races one after the other"

Walter Elliot



"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare
.



Relevant Pages

  • str_replace oddity
    ... I am using str_replace to strip double quotes. ... but the ghost remains and mysql continues to escape them. ... Liberty is a well-armed lamb contesting the vote." ...
    (php.general)
  • Re: RegExp DoubleQuote
    ... and recieved an error that the quotes don't match. ... Notice that you officially need to escape the as well when you put them in a tag. ... not work and I recieve an error about it being malformed. ... Jesse Houwing ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: compilation error message on tomcat 5.5.27
    ... What does your error message say? ... either escape any double quotes used within the string, ...
    (comp.lang.java.programmer)
  • regular expression xml help please
    ... anyone know how to return any quotes used inside a text node? ... what i want to do is escape those " with ' ... string so there will be multiple nodes per line, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: A critique of cgi.escape
    ... and quotes should always be escaped. ... Making cgi.escape always escape the '"' character would not break ... and would probably fix a few bugs in existing code. ...
    (comp.lang.python)