Learn PHP

addcslashes function

addcslashes — Quote string with slashes in a C style


string addcslashes ( string $str , string $charlist )

Returns a string with backslashes before characters that are listed in charlist parameter.

str - The string to be escaped.

charlist - A list of characters to be escaped. If charlist contains characters \n, \r etc., they are converted in C-like style, while other non-alphanumeric characters with ASCII codes lower than 32 and higher than 126 converted to octal representation.

When you define a sequence of characters in the charlist argument make sure that you know what characters come between the characters that you set as the start and end of the range.

					echo addcslashes('foo[ ]', 'A..z');
					// output:  \f\o\o\[ \]
					// All upper and lower-case letters will be escaped


		  		\f\o\o\[ \]		  

Be careful if you choose to escape characters 0, a, b, f, n, r, t and v. They will be converted to \0, \a, \b, \f, \n, \r, \t and \v, all of which are predefined escape sequences in C. Many of these sequences are also defined in other C-derived languages, including PHP, meaning that you may not get the desired result if you use the output of addcslashes() to generate code in those languages with these characters defined in charlist.

charlist like "\0..\37", which would escape all characters with ASCII code between 0 and 31.

Example 1

					$str="Welcome to studentsempire";  
					echo "Your String : ".$str;  
					echo "<br>"."By using 'addcslashes()' method your string: ".addcslashes($str,'T')."<br>"; 


		  		Your String : Welcome to studentsempire
By using 'addcslashes()' method your string: Welcome to studentsempire

Example 2

					$str="Welcome to studentsempire";  
					echo "Your String : ".$str;  
					echo "<br>"."By using 'addcslashes()' method your string: ".addcslashes($str,'a')."<br>"; 


		  		Your String : Welcome to studentsempire<br>By using 'addcslashes()' method your string: Welcome to studentsempire<br>		  

Example 3

					$str ="Welcome to studentsempire"."<br>";  
					echo "$str";  
					echo addcslashes($str,'A..Z')."<br>"; 


		  		Welcome to studentsempire
\Welcome to studentsempire

Example 4

					$str ="Welcome to studentsempire"."<br>";  
					echo "$str";  
					echo addcslashes($str,'a..z')."<br>";  


		  		Welcome to studentsempire
W\e\l\c\o\m\e \t\o \s\t\u\d\e\n\t\s\e\m\p\i\r\e<\b\r>

Example 5

					$str ="Welcome to studentsempire";  
					echo "Your string value is: ".$str."<br>";  
					echo "By using addcslashes() Function your value is : ".addcslashes($str,'a..m');   


		  		Your string value is: Welcome to studentsempire
By using addcslashes() Function your value is : W\e\l\co\m\e to stu\d\ents\e\mp\ir\e

PHP Tutorials






Echo and Print Statement

Data Types



Number Convert

PHP String

php variable substitution in string

php string element

php string function

php addcslashes function

php addslashes function

php get magic quotes gpc function

php get meta tags function

php urlencode function

PHP $ and $$ Variables

PHP constant

PHP Magic Constants

PHP Static Variable

PHP Super Globals

PHP Globals

PHP Server

PHP reserved variable get

PHP reserved variable post

PHP reserved variable FILES

PHP reserved variable Cookies

PHP reserved variable Session

PHP reserved variable Request

PHP reserved variable environment

PHP Operator

PHP Arithmetic Operator

PHP Comparison Operator

PHP Incrementing and Decrementing Operators

PHP Identical Operators

PHP Logical Operators

PHP String Operators

PHP Ternary Operators

PHP Execution Operators

PHP Operator Precedence

PHP Array Operator

PHP Class

PHP Class Inheritance

PHP constructor and destructor

PHP abstract class

PHP class access control

PHP statement

PHP If statement

PHP else statement

PHP else if statement

PHP control structure statement

PHP while loop

PHP do while loop

PHP for loop

PHP for each loop

PHP break statement

PHP continue statement

PHP declare statement

PHP return statement

PHP require statement

PHP include

PHP require once

PHP include once

PHP goto statement

PHP function

PHP function parameter

PHP function scope

PHP array

PHP array operator

PHP array element loop

PHP array foreach loop

PHP array multidimensional

PHP html forms

PHP get and post method

form redirect

file inclusion

file i/o