behz4d
behz4d

Reputation: 1847

a Slash adds to the string after cotation - PHP

For inserting strings into database, I apply this function on the string:

$string = strip_tags($string);
$string = htmlspecialchars($string);
$string = preg_replace('/\s+/', ' ', $string); // removing multiple spaces :-)
$string = preg_replace('/(?:\s\s+|\n|\t)/', ' ', $string);
$string = mysql_real_escape_string($string);

On my localhost while I test the app, I enter: Life's Interesting

and the exact string saves into db (Life's Interesting), then I uploaded my app on the real server, when I enter the same string, it saves: Life\'s Interesting in database!

Why is this happening on just the server and not on my local host? I'm using Wamp on my localhost. what configuration I need to change on the server so it saves right in db?

Thanks in advance

Upvotes: 0

Views: 71

Answers (1)

som
som

Reputation: 4656

Because magic_quotes_gpc

var_dump(magic_quotes_gpc())

var_dump magic quotes gpc in your both server. Your real server I think magic quotes is enabled by default.

Magic Quotes is a process that automagically escapes incoming data to the PHP script. It's preferred to code with magic quotes off and to instead escape the data at runtime, as needed.

More to read PHP Manual - Magic Quotes

Upvotes: 3

Related Questions