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 VALVE
This 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
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php