Computer >> Computer tutorials >  >> Programming >> PHP

addcslashes() function in PHP


The addcslashes() function returns the string with blackslashes.

Note − The addcslashes() function is case-sensitive

Syntax

addcslashes(str, characters)

Parameters

  • str − The string to be escaped

  • characters − The characters or range of characters to be escaped

Return

The addcslashes() function returns a string with backslashes in front of the specified characters.

Example

The following is an example −

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

Output

The following is the output −

First \World!

Example

Let us see another example −

<?php
   $str = addcslashes("First World!","a..r");
   echo($str);
?>

Output

The following is the output −

F\i\rst W\o\r\l\d!