Re: Very Weird Problem Continued
| From: | John W. Holmes | Date: | Sun, 15 Jun 2003 14:57:25 +0000 |
| Subject: | Re: Very Weird Problem Continued | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-151584@lists.php.net to get a copy of this message | ||
James Hicks wrote:
The following variable needs to be escaped before it can be submitted as an MySQL query. It seems that the \0 in this string is causing me the problem. I have tried several functions in an attempt to escape this variable. Anybody got any other suggestions. The resulting string should look like this: EBCO\\030774-006\\BUBBLER VALVE $variable = "EBCO\030774-006\BUBBLER VALVE"; Things I have tried so far that do not work. Every one of the following functions results in \030 being replaced with a weird character. echo addslashes($variable); echo str_replace("\","\\",$variable); echo mysql_escape_string($variable); Here is the result of all of the above functions ( notice weird character after EBCO and that all the functions successfully escape the second \ character in between the 6 and the B in BUBBLER): EBCO▒774-006\\BUBBLER VALVEThis works in all cases: $variable = 'EBCO\030774-006\BUBBLER VALVE'; echo addslashes($variable); echo str_replace('\\','\\\\',$variable); echo mysql_escape_string($variable); Where is this data actually coming from? Is it something you enter into a form and then need to put into a database and display on the page? Running any of those three options on your data entered into a form gave me the correct value, also. FYI: \0 is the NULL character. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ PHP|Architect: A magazine for PHP Professionals – www.phparch.com