Php addcslashes

From CoderLearner
Jump to: navigation, search

PHP function addcslashes

This function returns a string with backslashes in front.

Syntax addcslashes

  • string: string to use for assign the backslashes.
  • characters: a range of characters within the string that going to assign the backslashes.
addcslashes(string,characters)

Example 1

  • Add slash to front of the characters: out
<?php

$mylist = "I want to tell you how to do it";
$mynew_list = addcslashes($mylist, 'out');
echo $mynew_list;
?>

Output

I wan\t \t\o \tell y\o\u h\ow \t\o d\o i\t

Example 2

  • Add slashes to all characters: a..z (all lower case:a..z, all upper case:A..Z)
<?php

$mylist = "I want to tell you how to do it";
$mynew_list = addcslashes($mylist, 'a..zA..Z');
echo $mynew_list;
?>

Output

\I \w\a\n\t \t\o \t\e\l\l \y\o\u \h\o\w \t\o \d\o \i\t