PHP addcslashes() Function
Example
Add a backslash before the character "W":
Run Example »
Definition and Usage
The addcslashes() function returns a string with backslashes added before the specified characters.
**Note:** The addcslashes() function is case-sensitive.
**Note:** Be careful when applying addcslashes() to 0 (NULL), r (carriage return), n (newline), t (tab), f (form feed) and v (vertical tab). In PHP, \0, \r, \n, \t, \f and \v are predefined escape sequences.
Syntax
addcslashes(
string,characters
)
| Parameters | Description |
|---|---|
| string | Required. Specifies the string to escape. |
| characters | Required. Specifies the characters or character ranges to escape. |
Technical Details
| Return Value: | Returns the escaped string. |
|---|---|
| PHP Version: | 4+ |
More examples
Example 1
Add backslashes before specific characters in a string:
"; echo addcslashes($str,'m').""; echo addcslashes($str,'H')."
"; ?>
Run Example »
Example 2
Add backslashes before characters within a range in a string:
"; echo addcslashes($str,'A..Z').""; echo addcslashes($str,'a..z')."
"; echo addcslashes($str,'a..g'); ?>
Run Example »
PHP String Reference Manual