addcslashes()
addcslashes() — Quote string with slashes in a C style.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Returns a string with backslashes before characters that are listed in characters parameter.
Signature
addcslashes(string $string, string $characters): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | The string to be escaped. |
| $characters | string | A list of characters to be escaped. If characters contains characters \n, \r etc., they are converted in C-like style, while other non-alphanumeric characters with ASCII codes lower than 32 and higher than 126 converted to octal representation. |
Return value
Returns the escaped string.
Example
A runnable snippet:
$not_escaped = "PHP isThirty\nYears Old!\tYay to the Elephant!\n"; $escaped = addcslashes($not_escaped, "\0..\37!@\177..\377"); echo $escaped;
See also
stripcslashes(), stripslashes(), addslashes(), htmlspecialchars(), quotemeta()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page addcslashes() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.