PHP addcslashes() Function

Last Updated:

PHP addcslashes()

The addcslashes() function is used to add backslashes before the specified characters in a given string.

Note: If you choose to escape characters 0, a, b, f, n, r, t and v. They will be converted to \0, \a, \b, \f, \n, \r, \t and \v, all of which are predefined escape sequences in PHP.

Example

PHP Compiler
<?php $str = "This Is Text"; echo addcslashes($str, "T"); ?>

Syntax

addcslashes(str, char_list)

Parameter Values

ValueTypeExplanation
str Required Specifies the string to be escaped.
char_list Required Specifies the sequence of characters.

Return Value

ValueExplanation
String Returns a string with backslashes before characters that are listed in char_list parameter.

More Example

Example

PHP Compiler
<?php $str = "This Is Text"; echo "All T (uppercase only) Characters <br>"; echo addcslashes($str, "T") . "<br>"; echo "All Characters from A to Z (uppercase only) <br>"; echo addcslashes($str, "A..Z") . "<br>"; echo "All Characters from a to z (lowercase only) <br>"; echo addcslashes($str, "a..z") . "<br>"; echo "All Characters from A to z (uppercase and lowecase) <br>"; echo addcslashes($str, "A..z") . "<br>"; ?>

Share this Page

Meet the Author