addcslashes
Escape characters in a string using backslashes in C style
addcslashes()
function returns a string that adds a backslash before the specified character.
Note: addcslashes()
function is case sensitive.
Note: Be careful when applying addcslashes()
to the following characters: 0 (NULL), r (carriage return), n (line break), f page break), t (tab), and v (vertical tab). In PHP, \0, \r, \n, \t, \f and \v are predefined escape sequences.
Add a backslash before the character "A":
<?php $str = addcslashes ( "A001 A002 A003" , "A" ) ; echo ( $str ) ; ?>
Try it yourself
Add a backslash to a specific character in a string:
<?php $str = "Welcome to Shanghai!" ; echo $str . "<br>" ; echo addcslashes ( $str , 'm' ) . "<br>" ; echo addcslashes ( $str , 'H' ) . "<br>" ; ?>
Try it yourself
Add a backslash to characters within a range in a string:
<?php $str = "Welcome to Shanghai!" ; echo $str . "<br>" ; echo addcslashes ( $str , 'A..Z' ) . "<br>" ; echo addcslashes ( $str , 'a..z' ) . "<br>" ; echo addcslashes ( $str , 'a..g' ) ; ?>
Try it yourself
addcslashes ( string , characters )
parameter | describe |
---|---|
string | Required. Specifies the string to be escaped. |
Characters | Required. Specifies the characters or range of characters to be escaped. |