The addslashes Function

The addslashes function escapes some characters in a string with a backslash. The single quote ', double quote ", backslash \ and NUL are escaped.

Syntax

phpaddslashes(string $string): string

Example

Let's escape quotes using our function:

php<?php
  echo addslashes('id="eee"');
?>

Code execution result:

php'id=\"eee\"'

See Also

  • the stripslashes function,
    which performs the reverse operation