The addcslashes() function is a built-in function in PHP. The addcslashes() function is used to add backslashes before some specified characters in a given string.
string addcslashes($string, $characters)
Parameters: This function accepts two parameters as shown in the above syntax and are described below:
- $string: This parameter specifies the input string which is needed to be escaped. Or we can also say that the string in which we want to add backslashes before some specified characters.
- $characters: This parameter specifies a character or sequence of characters which we want to escape in the input string by adding backslashes before them. We can specify a range of characters as ‘a..z’. That is the start character of the range followed by two dots and the ending character.
Note: Please use characters like a,b,n,t etc carefully as this parameter as \a,\b,\n,\t are predefined escape sequences and have some special meaning. So, we might not get the desired result.
Return Value: This function returns a escaped string which is the input string $string with backslashes added before $characters.
Input: $string = "GeeksforGeeks" $characters = 'e' Output: G\e\eksforG\e\eks Input: $string = "GeeksforGeeks" $characters = 'a..k' Output: G\e\e\ksnG\e\e\ks
Below programs illustrate the addcslashes() function in PHP:
- How to get the function name inside a function in PHP ?
- PHP | Ds\Map first() Function
- p5.js | str() function
- PHP | sin( ) Function
- D3.js | d3.max() function
- p5.js | hex() function
- CSS | url() Function
- D3.js | d3.map.set() Function
- PHP | Ds\Map get() Function
- PHP | abs() Function
- PHP Ds\Map sum() Function
- CSS | hsl() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.