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
https://forums.phpfreaks.com/topic/95138-php-adds-slashes-to-text/
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....

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.