Black Friday sale is now on! 50% off Laravel: The Modular Way. Learn more

Magic Quotes

David Carr

PHP & MySQL Tutorials

    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 

    Laravel Modules Book by David Carr

    Help support the blog so that I can continue creating new content!

    Subscribe to my newsletter

    Subscribe and get my books and product announcements.

    © 2009 - 2022 DC Blog. All code MIT license. All rights reserved.