Table of Contents

Syntax

string addslashes(string $str)

(PHP 4, PHP 5)

$str The string to manipulate (add escape characters)
RETURNS Returns the modified string with special characters escaped

What it Does

Escapes a specified list of charcters in a string with a backslash (\). This is useful for certain programs which require special characters to be escaped. Specifically, if you are going to insert or update data in a MySQL database, these slashes are necessary to prevent errors and hacking attempts.

Your PHP interpreter may add slashes to your GET, POST, and COOKIE variables automatically. This is known as magic quotes. See the function get_magic_quotes_gpc for more information.

Example

$test = addslashes("Why can't we be friends?");
echo $test;

Outputs:

Why can\'t we be friends?
 
addslashes.txt · Last modified: 2008/04/18 14:00 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki