Jump to content

PHP adds slashes to text


biscoe916

Recommended Posts

I have a little message board app. It works ok but for some reason PHP is adding slashes before certain punctuation.... Why? And how do i stop this?

 

So if i were to type this into the form:

 

Hi I'm tired.

It would be displayed on the page(and entered into the database) as:

 

Hi I\'m tired.

 

How can i fix this.

 

Is the fact that im using: mysql_real_escape_string();  the problem?

 

 

Link to comment
Share on other sites

"Yeah Dude.  That definitely be the problem.  You need to use another command like stripslasshes() upon retrieving your data.  But don't tell anybody else about this please."

 

 

Sarcasm?  School project you want people to fail?

 

Anyway, look into magic quotes.....

 

What ever data is entered is being slashed automatically, and then you're slashing it again....

Link to comment
Share on other sites

When you have magic quotes on (I personally can't stand magic quotes), it's the equivalent of running all of the REQUEST variables through addslashes();

 

To demonstrate, it would be like this, except done automatically:

 

function stripslashes_deep($value) {
$value = is_array($value) ?
			array_map('addslashes_deep', $value) :
			addslashes($value);
return $value;
}

if(isset($_GET)) $_GET = stripslashes_deep($_GET);
if(isset($_POST)) $_POST = stripslashes_deep($_POST);
if(isset($_COOKIE)) $_COOKIE = stripslashes_deep($_COOKIE);

 

 

That mean's that addslashing()ing again would be like doing:

 

$str = "This is Corbin's string";
$str = addslashes($str);
$str = addslashes($str);
//$str is now "This is Corbin\\\'s string";

 

Then, when putting that into the database, MySQL would interpret the first \\ as an escaped \, and \' would be interpretted as ', leaving you with \'.

 

As for outputting on the page, you would have "This is Corbin\'s string" in the raw variable, which is what would be printed.

 

Anyway, just google magic quotes, or look on http://php.net/addslashes , and it will explain what magic quotes is/what it does.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.