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');

Result:

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!"');

Result:

She said, \"Great!\"

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

Next: PHP echo Function

Link to this page: If you find this page useful, we encourage you to link to this page. Simply copy and paste the code below to your website, blog, or profile.




More 1Keydata Tutorials



PHP addslashes
PHP echo
PHP explode
PHP htmlentities
PHP htmlspecialchars
PHP implode
PHP md5
PHP number_format
PHP print
PHP str_replace
PHP strlen
PHP strpos
PHP strstr
PHP substr
PHP trim

PHP Syntax

PHP Sitemap

PHP Resources