Re: how do I just escape double quotes within a string?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You could use addslashes():
http://us3.php.net/manual/en/function.addslashes.php

Or, the code you mentioned below, could be rewritten like:
str_replace("\"","\\"",$code);
or
str_replace('"','\"',$code);

And if you're doing it for a MySQL query call, then you want to use mysql-real-escape-string() instead of all that mess above:
http://www.php.net/manual/en/function.mysql-real-escape-string.php

What's happening with the example you gave is that you're having a conflict with using the same type of string encloser (what's the proper word for single and double quotes in this case? hah).

""" = "" with a dangling ".  Error.

"\"" = a string containing just a double quote.

Everything inside "" is interpreted.

Everything inside '' is taken literally.

'"' = a string containing a double quote

''' = '' with a dangling ' on the end
'\'' = a string containing '  (I think.. I think this is the only exception to no-interpretation-within-single-quotes)

Some more information on single and double quotes here:
http://us3.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

-TG

= = = Original message = = =

If I use add slashes, it strips everything, I just want to replace all the
double quotes with slash double quote but this, of course, throws errors:

str_replace(""","\"",$code);


Thanks!


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux