Latest web development tutorials

PHP addcslashes () function

PHP String Reference PHP String Reference

Examples

In a backslash before the "W":

<?php
$str = addcslashes("Hello World!","W");
echo($str);
?>

Running instance »

Definition and Usage

addcslashes () function returns the character in front of the specified string to add the backslash.

Note: addcslashes () function is case-sensitive.

NOTE: to 0 (NULL), r (carriage return), n (newline), t (feed), f (tabs) and v (vertical tab) application addcslashes () Be careful.In PHP, \ 0, \ r, \ n, \ t, \ f and \ v escape sequences are predefined.


grammar

addcslashes( string,characters )

参数 描述
string 必需。规定要转义的字符串。
characters 必需。规定要转义的字符或字符范围。

technical details

return value: Returns the escaped string.
PHP version: 4+


More examples

Example 1

Adding to a string of specific characters backslash:

<?php
$str = "Welcome to my humble Homepage!";
echo $str."<br>";
echo addcslashes($str,'m')."<br>";
echo addcslashes($str,'H')."<br>";
?>

Running instance »

Example 2

Adding to a string of characters within a range of backslash:

<?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');
?>

Running instance »


PHP String Reference PHP String Reference