How to Escape Quotes in PHP

The "addslashes" function adds the backslash character to quotes. The backslash character is the escape character, which means it tells the compiler to use the literal character instead of using the quotes to terminate a string. You use the escape character when you need to pass special characters to a database that stores data submitted by your readers.

Instructions

    • 1

      Right-click the PHP file you want to edit and select "Open With." Click the PHP file editor you want to use to change the code.

    • 2

      Locate the string that contains the quotes. The following code shows you how to create a PHP string, if you do not already have one defined:

      $var = 'this string with a quote "';

    • 3

      Add the "addslashes" function to the string. The following code shows you how to add the escape backslash character in front of the quotes:

      $var = addslashes($var);

Related Searches:

References

Comments

Related Ads

Featured