php-doc-en/reference/strings/functions/addslashes.xml
Chris Wright 98751e689d Proper noun casing fix
-- 
Provided by anonymous 48275

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@334702 c90b9560-bf6c-de11-be94-00142212c4b1
2014-09-01 16:21:45 +00:00

138 lines
4.2 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.addslashes">
<refnamediv>
<refname>addslashes</refname>
<refpurpose>Quote string with slashes</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>addslashes</methodname>
<methodparam><type>string</type><parameter>str</parameter></methodparam>
</methodsynopsis>
<para>
Returns a string with backslashes before characters that need to be
escaped. These characters are single quote (<literal>'</literal>),
double quote (<literal>"</literal>), backslash
(<literal>\</literal>) and NUL (the &null; byte).
</para>
<para>
An example use of <function>addslashes</function> is when you're
entering data into string that is evaluated by PHP. For example,
<literal>O'Reilly</literal> is stored in $str, you need to escape
$str. (e.g. eval("echo '".addslashes($str)."';"); )
</para>
<para>
To escape database parameters, DBMS specific escape function
(e.g. <function>mysqli_real_escape_string</function> for MySQL or
<function>pg_escape_literal</function>, <function>pg_escape_string</function>
for PostgreSQL) should be used for security reasons. DBMSes have
differect escape specification for identifiers (e.g. Table name,
field name) than parameters. Some DBMS such as PostgreSQL provides
identifier escape
function, <function>pg_escape_identifier</function>, but not all
DBMS provides identifier escape API. If this is the case, refer to
your database system manual for proper escaping method.
</para>
<para>
If your DBMS doesn't have an escape function and the DBMS
uses <literal>\</literal> to escape special chars, you might be
able to use this function only when this escape method is adequate for
your database. Please note that use
of <function>addslashes</function> for database parameter escaping
can be cause of security issues on most databases.
</para>
<para>
The PHP directive <link linkend="ini.magic-quotes-gpc">
magic_quotes_gpc</link> was <literal>on</literal> by default before
PHP 5.4, and it essentially ran <function>addslashes</function> on
all GET, POST, and COOKIE data. Do not
use <function>addslashes</function> on strings that have already
been escaped with
<link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> as you'll
then do double escaping. The function
<function>get_magic_quotes_gpc</function> may come in handy for
checking this.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>str</parameter></term>
<listitem>
<para>
The string to be escaped.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the escaped string.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>An <function>addslashes</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$str = "Is your name O'Reilly?";
// Outputs: Is your name O\'Reilly?
echo addslashes($str);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>stripcslashes</function></member>
<member><function>stripslashes</function></member>
<member><function>addcslashes</function></member>
<member><function>htmlspecialchars</function></member>
<member><function>quotemeta</function></member>
<member><function>get_magic_quotes_gpc</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->