PHP addslashes Functions

PHP Tutorial > String Functions > addslashes Function

The PHP addslashes function is used to add slashes to certain characters in a string. Those characters are single quote ('), double quote ("), and the NULL character. This function is useful when we try to insert strings into a database.

The syntax of the addslashes function is:

addslahes ('string')

Let's take a look at the examples below:

Example 1

print addslashes ('1keydata');



In Example 1, nothing changes because the string does not contain single quote, double quote, or the NULL character.

Example 2

print addslahes ('She said, "Great!"');


She said, \"Great!\"

In Example 2, a backslash is added to the left of the double quotes.

Next: PHP echo Function

Copyright © 2017  All Rights Reserved.  Privacy Policy   About   Contact