Programming |
PHP |
26 January 2012
Written by Khabza
The addcslashes() function returns a string with backslashes in front of the specified characters.
Syntax
addcslashes(string,characters)
Parameter
string is a required. Specifies the string to check
characters is a required. Specifies the characters or range of characters to be affected by addcslashes()
Note: Be careful using addcslashes() on 0, r, n and t. In PHP, \0, \r, \n and \t are predefined escape sequences.
Problem
We will add backslashes to certain characters in a string: add php openinh tag and closing tag to following code,
$str = "Hello, my name is Khabza.";
echo $str."<br \>";
echo addcslashes($str,'m')."<br \>";
echo addcslashes($str,'K')."<br \>";
Solution
Hello, my name iskhabza.
Hello, \my na\me is Kabza.
Hello, my name is \Kabza.