Easy Tutorial
❮ Func Date Getdate Func Ftp Chdir ❯

PHP addslashes() Function

PHP String Reference Manual

Example

Add a backslash before each double-quote (").


Definition and Usage

The addslashes() function returns a string with backslashes added before predefined characters.

The predefined characters are:

Tip: This function can be used to prepare strings for storage in a database and for database query statements.

Note: By default, the PHP directive magic_quotes_gpc is on and automatically applies addslashes() to all GET, POST, and COOKIE data. Do not use addslashes() on strings that have already been escaped with magic_quotes_gpc as it will cause double escaping. In such cases, you can use the function get_magic_quotes_gpc() for detection.


Syntax

Parameter Description
string Required. Specifies the string to be escaped.

Technical Details

Return Value: Returns the escaped string.
PHP Version: 4+
--- ---

More Examples

Example 1

Add backslashes to predefined characters in a string:


❮ Func Date Getdate Func Ftp Chdir ❯