PHP addcslashes

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : addcslashes() function

Description

The addcslashes() function is used to add backslashes in front of the specified characters in a string. 

Note : In PHP � (NULL), (carriage return), (newline), f (form feed), v (vertical tab) and (tab) are predefined escape sequences.

Version

(PHP 4 and above)

Syntax

 addcslashes (string_name, charlist)

Parameters

Name

Description

Required /
Optional

Type

string_name

The string to be escaped..

Required

String

charlist

Sequence of characters.

Optional

String

Return values

The escaped string.

Value Type : String.

Pictorial Presentation :

php-string-addcslashes()

Example :

  1. echo addcslashes('w3resource.com', '0..9');  

  2. echo '
    ';  

  3. echo addcslashes('w3resource.com', '.');  

  4. echo '
    ';  

  5. echo addcslashes('Welcome to w3resource.com','t');  

  6. echo '
    ';  

  7. echo addcslashes('Welcome to w3resource.com','A..Z');  

  8. echo '
    ';  

  9. ?>   

Output :

w3resource.com
w3resource.com
Welcome o w3resource.com
Welcome to w3resource.com