Tutorials, PHP & MySQL

Magic Quotes

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.

//Example:
$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 

David Carr

David Carr

For the past 12 years, I’ve been developing applications for the web using mostly PHP. I do this for a living and love what I do as every day there is something new and exciting to learn.

In my spare time, the web development community is a big part of my life. Whether managing online programming groups and blogs or attending a conference, I find keeping involved helps me stay up to date. This is also my chance to give back to the community that helped me get started, a place I am proud to be apart of.

Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie, staying in playing games on the sofa or planning a trip to someplace I’ve never been before.