PHP addcslashes() Function

You are Here:

PHP addcslashes()

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

Note: 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 PHP.

Example

PHP Compiler
<?php $str = "This Is Text"; echo addcslashes($str, "T"); ?>

Output

\This Is \Text

Syntax

addcslashes(str, char_list)

Parameter Values

ValueTypeExplanation
strRequiredSpecifies the string to be escaped.
char_listRequiredSpecifies the sequence of characters.

Return Value

ValueExplanation
StringReturns a string with backslashes before characters that are listed in char_list parameter.

More Example

Example

PHP Compiler
<?php $str = "This Is Text"; echo "All T (uppercase only) Characters <br>"; echo addcslashes($str, "T") . "<br>"; echo "All Characters from A to Z (uppercase only) <br>"; echo addcslashes($str, "A..Z") . "<br>"; echo "All Characters from a to z (lowercase only) <br>"; echo addcslashes($str, "a..z") . "<br>"; echo "All Characters from A to z (uppercase and lowecase) <br>"; echo addcslashes($str, "A..z") . "<br>"; ?>

Output

All T (uppercase only) Characters \This Is \Text All Characters from A to Z (uppercase only) \This \Is \Text All Characters from a to z (lowercase only) T\h\i\s I\s T\e\x\t All Characters from A to z (uppercase and lowecase) \T\h\i\s \I\s \T\e\x\t

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on PHP with examples for quick and easy learning.

We are working to cover every Single Concept in PHP.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author