PHP addcslashes Function

The PHP addcslashes function is used to adds backslashes in front of the specified characters. This function is case-sensitive.

PHP addcslashes Function

The PHP addcslashes function is used to adds backslashes in front of the specified characters.

Syntax

addcslashes(string, charlist);

  • This function is case-sensitive.
  • Both the parameters are required.
  • This function returns the escaped string.

This function takes two parameters. The first parameter is the string to be escaped and the second parameter is a list of characters to be escaped.

Example

<?php 
    $data = addcslashes("This is addcslashes function","i");
    echo($data); 
?>

Output

Th\is \is addcslashes funct\ion

You can also add backslashes to a range of characters in a string.

Example

<?php
    $data = addcslashes("This is addcslashes function","A..z"); //Adds backslashes to both uppercase and lowercase characters.
    echo "$data"."<br>"; //Appends HTML line-break.
    echo addcslashes("THIS Is Another Example", "a..z"); //Add backslashes only before lowercase characters.
?>

\T\h\i\s \i\s \a\d\d\c\s\l\a\s\h\e\s \f\u\n\c\t\i\o\n  
THIS I\s A\n\o\t\h\e\r E\x\a\m\p\l\e

Learn more about other PHP string handling functions.


Share Tweet Send
Loading...
You've successfully subscribed to Geekinsta
Great! Next, complete checkout for full access to Geekinsta
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.