Magic Quotes

David Carr

1 min read - 15th May, 2011

This tutorial will explain what magic quotes are and how to use them. When Magic Quotes are enabled will automatically escape single and double quotation marks.

This helps prevent problems in php/html.

There are two types of Magic Quotes:

magic_quotes_gpc which works for forms, urls and cookies (gpc stands for get, post and cookie).

magic_quotes_runtime which works for data from external files and databases.

If there is an apostrophe like: dave's then the result would be daves to get round this you can use the function stripslashes() This function removes any backslashes found.

$text = "this is dave's data";

if magic quotes are activated on the server then the result when printed would be:

this is daves data

To get round this use stripslashes()

$text stripslashes($text);
$text = "this is dave's data";

the result would then be:

this is dave's data

A doubles backslash will be turned into a single backslash using the stripslashes() function 

Add a comment

Copyright © 2006 - 2024 DC Blog - All rights reserved.