Logo Luan Morina
Escape special characters in a PHP string

To escape special characters in a PHP string, you can use the backslash \ followed by the character you want to insert. For example \$ for a dollar sign to prevent variable interpolation.

Other examples:

  • \\ for a backslash
  • \' for a single quote
  • \" for a double quote
  • \n for a new line
  • \r for a carriage return
  • \t for a tab

Escaping special characters from a posted value

To escape all special characters from a posted value, you can use this function:

$user_last_name = mysqli_real_escape_string($conn, $_POST['user_last_name']);
   Change MySQL Table Column Position