Add a backslash before the character "W":
<?php $str = addcslashes("Hello World!","W");echo($str); ?>The addcslashes() function returns a string with a backslash added before the specified character.
Note: The addcslashes() function is case-sensitive.
Note: Be careful when applying addcslashes() to 0 (NULL), r (carriage return), n (line feed), t (form feed), f (tab), and v (vertical tab). In PHP, , r, n, t, f, and v are predefined escape sequences.
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. |
Return value: | Returns the escaped string. |
---|---|
PHP version: | 4+ |
Add backslashes to specific characters in a string:
<?php$str = "Welcome to my humble Homepage!";echo $str."<br>";echo addcslashes($str,'m')."<br>";echo addcslashes($str,'H ')."<br>";?>Add backslashes to a range of characters in a string:
<?php$str = "Welcome to my humble Homepage!";echo $str."<br>";echo addcslashes($str,'A..Z')."<br>";echo addcslashes($str ,'a..z')."<br>";echo addcslashes($str,'a..g');?>