Question #6304
Submitted by Answiki
on 06/22/2022 at 07:39:54 PM UTC
How to escape special characters in PHP?
Merged questions
Answer
Submitted by Answiki
on 06/22/2022 at 07:39:33 PM UTC
The PHP function addslashes() is used to escape special characters from a string. The function automatically adds a backslash before each of the following characters:
- single quote ( ' )
- double quote ( " )
- backslash ( \ )
- the NUL character
For example:
$string = 'He says "John".';
$string = addslashes ($string);
// Displays: He says \"John\".
echo $string;
See also:
Question by Answiki 06/22/2022 at 07:39:54 PM
How to escape special characters in PHP?
Answer by Answiki on 06/22/2022 at 07:39:33 PM
The PHP function addslashes() is used to escape special characters from a string. The function automatically adds a backslash before each of the following characters:
- single quote ( ' )
- double quote ( " )
- backslash ( \ )
- the NUL character
For example:
$string = 'He says "John".';
$string = addslashes ($string);
// Displays: He says \"John\".
echo $string;
See also:
Question by Answiki 06/22/2022 at 07:36:35 PM
What is the purpose of the addslashes() function in PHP?
Question by Answiki 06/22/2022 at 07:36:29 PM
What is the purpose of the addslashes function in PHP?
| # | ID | Query | URL | Count |
|---|---|---|---|---|
| 0 | 12999 | en | https://en.ans.wiki/6304/how-to-escape-special-characters-in-php | 8 |
Icons proudly provided by Friconix.