Skip to main content

Posts

Showing posts from October, 2009

Add slashes, strip slashes, and magic quotes...

Today, I was fixing some bug related to text processing in one of our projects. When saving a text that was typed in a text area, for some characters, additional slashes are added.

Ex: TEST\TEST becomes TEST\\TEST

This was because, the "magic quotes gpc" setting is turned on, and the slashes are not striped after retrieving the saved data. When you saving the data again and again, additional slashes are added due to this situation. Actually, these slashes should be added before you're entering data into a database. The "magic quotes gpc" does it automatically in PHP. You can turn this setting off, and do it manually using the "addslashes" function as well. After all, it is advisable to write your code so that it handles both of these situations. Something like given below can be used for this.
if (!get_magic_quotes_gpc()) {
$notification->setSubject(addslashes($subject));
$notification->setContent(addslashes($content));
} else {
$notifica…