Re: escaping (backslashing) backslashes?
| From: | Joe Lloyd | Date: | Wed, 04 Oct 2000 17:03:29 +0000 |
| Subject: | Re: escaping (backslashing) backslashes? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-3317@lists.php.net to get a copy of this message | ||
Have a look at:
http://www.php.net/manual/function.addslashes.php
http://www.php.net/manual/function.stripslashes.php
Jack McKinney wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
>
> Before putting a string into a query for MySQL, one should escape
> the quotes in it:
>
> $value = ereg_replace("'","''",$value);
>
> or:
>
> $value = ereg_replace("'","\\'",$value);
>
> This second one actually works in that MySQL accepts the backslash as
> an escape, and two backslashes in PHP get escaped into one, so that the
> string only has the single backslash in front of the quote, but not two.
> Suppose, however, that you need to insert a backslash into the database.
> Specifically, the user enters a backslash into a form. I'd like to escape
> this. In MySQL, doubling the backslash (i.e., backslashing the backslash)
> does the trick:
>
> UPDATE sometable SET somefield = '\\'.
>
> However, this PHP statement:
>
> $value = ereg_replace("\\","\\\\",$value)
>
> gives me:
>
> Warning: REG_EESCAPE in /var/www/docs/test.php on line 5
>
> This only occurs at runtime (i.e., the page parses and displays, but
> when I submit the form, thus causing the ereg_replace line to actually
> be executed, I get this error).
>
> How do I escape the escape?
>
> - --
> "Restore your inalienable human rights. Jack McKinney
> Vote Libertarian. http://www.lp.org
> http://www.lorentz.com
> F4 A0 65 67 58 77 AF 9B FC B3 C5 6B 55 36 94 A6 jackmc@lorentz.com
>
> -----BEGIN PGP SIGNATURE-----
> Version: 2.6.2
>
> iQCVAwUBOdtgTUZx0BGJTwrZAQESrwP+OGaas699RtSglFdmXLIQFHfh8J5LDCmd
> BOUS/07+87q/cNVGhm0K7y96AzdOUDyKKK8YLMNmad5SGXo+ocbAVEN0xpkHJPIJ
> YrVw9au0kltVEieBgwxgO7NNs4syOV3CWvD1QZNwusZhY2nPHm9uFgvuA7+4GNfx
> 4iKLCyVlP/A=
> =DeL1
> -----END PGP SIGNATURE-----
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
************************************************************************
* Fear is the path to the darkside... *
* Fear leads to anger, anger leads to hate, hate leads to suffering...*
* Suffering is caused by Microsoft... *
************************************************************************
* Joe Lloyd joe@soundprint.org http://www.soundprint.org
*
* Online Manager System Administrator Web Designer *
************************************************************************