English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP addcslashes() Function Usage and Example

PHP String Character String Functions Manual

    The addcslashes() function is used to escape characters in a string using C language style backslashes

Syntax

string addcslashes ( string $str , string $charlist )

Definition and Usage

Returns a string that adds a backslash before each character that belongs to the parameter charlist list.

Return Value

It returns the escaped string

Parameter

Serial NumberParameters and Descriptions
1

str

String to be escaped

2

charlist

If charlist contains characters such as \n, \r, etc., they will be converted in C language style, while other non-alphanumeric characters and ASCII codes below 32 and above 126 All characters are converted to octal representation.
When defining the character sequence in the charlist parameter, it is necessary to indeed know what characters are between the start and end range that you have set.

Online Example

Try the following example

<?php
    echo addcslashes("zoo['.']", 'z..A');
// Output: \zoo['\.']
?>
Test and See ‹/›

Output Result:

\zoo['\.']

PHP String Character String Functions Manual