English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP addslashes() Function Usage and Example

PHP String Character String Functions Manual

The addslashes() function is used to quote strings.

Syntax

string addslashes ( string $str )

Returns a string with backslashes added before certain characters for the need of database query statements, etc. These characters are single quotes ('), double quotes (\
PHP 5.4 Before PHP instruction magic_quotes_gpc is set to on by default, actually all GET, POST, and COOKIE data are escaped with addslashes(). Do not use addslashes() on strings that have already been escaped by magic_quotes_gpc, as this will cause double escaping. In such cases, you can use the function get_magic_quotes_gpc() to check.

Return Value

It returns the escaped string

Parameter

Serial NumberParameter and Description
1

str

String to be escaped

Online Example

Try the following example

<?php
   $str = "Is your name sai Right?";
   echo addslashes($str);
?>

PHP String Character String Functions Manual