addcslashes() : adding slashes in a C style

$string="Hello welcome to plus2net Php section";
echo addcslashes($string,'e');
Output of this is here
H\ello w\elcom\e to plus2n\et Php s\ection 
Note in all places char e is escaped by adding a slashes.

These chars are escaped by adding backslashes.
single quote (')
double quote (")
backslash (\)
NUL (the NUL byte)
Here is the syntax
string addcslashes(string,string or charlist)
Returns the escaped string.

Here are some examples
$str = "Welcome  'to plus2net PHP section";
echo addcslashes($str,"'");
Welcome \'to plus2net PHP section

Escaping more than one char

$string="Hello welcome to plus2net Php section";
echo addcslashes($string,'c,o,n');
Output is here
Hell\o wel\c\ome t\o plus2\net Php se\cti\o\n 

For a series of chars

$string="Hello welcome to plus2net Php section";
echo addcslashes($string,'a..z');
Output is here
H\e\l\l\o \w\e\l\c\o\m\e \t\o \p\l\u\s2\n\e\t P\h\p \s\e\c\t\i\o\n 
Note that all upper case chars are not escaped

Example 2: Escaping Digits in a String

$str = "Product123";
$escaped_str = addcslashes($str, '0..9');
echo $escaped_str; // Outputs: Product\1\2\3

Example 3: Escaping Special Characters

$str = "Hello! How are you?";
$escaped_str = addcslashes($str, '!');
echo $escaped_str; // Outputs: Hello\! How are you?

String Functions addslashes() Remove HTML tags
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer