>I'm getting multiple backslashes in data I get out of a mysql database.

That's crazy...

You'd have to be adding an awful lot of backslashes *before* you put it in
there.

MySQL "eats" up one (1) set of \s when it "reads" data.

>1. $string  = stripslashes($string);   - Doesn't do anything

Sure it does!

$string = "insert into names(name) values('Conan O\\'Brien')";
print("Before: $string<BR>\n");
$string  = stripslashes($string);
print("After: $string<BR>\n");

>2. $string = ereg_replace("\\\\\\", "", $string); - Doesn't do anything

Try it with \\\\ maybe.

>3. $string = ereg_replace("\\", "", $string); - Gives the following error
>message:
>Warning: REG_EESCAPE in script.php on line 1684

Here's why:

PHP turns "\\" into "\"
Regex sees "\" and is looking for the *next* character after that to
'escape' it.
There ain't no next character, and that's just wrong.

"\\\\" would work like this:

PHP turns that into:  "\\"  (Each "pair" of \ in "\\\\" turns into one \)
Regex then sees "\\" and turns that into: "\\"

Or, let's assume that the '.' character is "special" in Regex.

You'd need "\\." in PHP to get a non-special '.' in Regex.

Here's why:

PHP turns "\\." into "\."
Regex sees "\." and knows that you want an actual '.', not the special
character '.' that is a wild-card.

>None of these have worked.  Any thoughts on how to get rid of them? I'm
>going batty.

My first guess is you have Magic Quotes "on" in php.ini *AND* you are using
addslashes() before you insert the data.

Another possibility is that your FORMs are passing the strings along as you
go...

Here's the deal:

The whole point of MagicQuotes and addslashes is to *prepare* data to be
inserted into a database.

If you choose *not* to insert that data, and spew it out to the browser
either in a TEXTBOX or in an INPUT TYPE=HIDDEN, then you need to use
stripslashes() at that point.

Otherwise, you've failed to remove the 'extra' slashes that were added in
anticipation of you using that data in a database query.

Use "View Source" in your browser as you work on this.

HTML *also* uses \ in some situations as an escape character, and you can
confuse yourself very easily by looking at browser output, instead of what's
really there.

-- 
Like Music?  http://l-i-e.com/artists.htm


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

Reply via email to