<HTML ><HEAD ><TITLE >addcslashes</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="String functions" HREF="ref.strings.html"><LINK REL="PREVIOUS" TITLE="String functions" HREF="ref.strings.html"><LINK REL="NEXT" TITLE="addslashes" HREF="function.addslashes.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="ref.strings.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.addslashes.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.addcslashes" ></A >addcslashes</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN88999" ></A ><P > (PHP 4 )</P >addcslashes -- Quote string with slashes in a C style</DIV ><DIV CLASS="refsect1" ><A NAME="AEN89002" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >addcslashes</B > ( string str, string charlist)<BR ></BR ><P > Returns a string with backslashes before characters that are listed in <TT CLASS="parameter" ><I >charlist</I ></TT > parameter. It escapes <TT CLASS="literal" >\n</TT >, <TT CLASS="literal" >\r</TT > etc. in C-like style, characters with ASCII code lower than 32 and higher than 126 are converted to octal representation. </P ><P > Be careful if you choose to escape characters 0, a, b, f, n, r, t and v. They will be converted to \0, \a, \b, \f, \n, \r, \t and \v. In PHP \0 (<TT CLASS="constant" ><B >NULL</B ></TT >), \r (carriage return), \n (newline) and \t (tab) are predefined escape sequences, while in C all of these are predefined escape sequences. </P ><P > <TT CLASS="parameter" ><I >charlist</I ></TT > like "\0..\37", which would escape all characters with ASCII code between 0 and 31. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN89021" ></A ><P ><B >Example 1. <B CLASS="function" >addcslashes()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$escaped = addcslashes($not_escaped, "\0..\37!@\177..\377");</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > When you define a sequence of characters in the charlist argument make sure that you know what characters come between the characters that you set as the start and end of the range. <DIV CLASS="informalexample" ><A NAME="AEN89026" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >echo addcslashes('foo[ ]', 'A..z'); // output: \f\o\o\[ \] // All upper and lower-case letters will be escaped // ... but so will the [\]^_` and any tabs, line // feeds, carriage returns, etc.</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > Also, if the first character in a range has a lower ASCII value than the second character in the range, no range will be constructed. Only the start, end and period characters will be escaped. Use the <A HREF="function.ord.html" ><B CLASS="function" >ord()</B ></A > function to find the ASCII value for a character. <DIV CLASS="informalexample" ><A NAME="AEN89029" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >echo addcslashes("zoo['.']", 'z..A'); // output: \zoo['\.']</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > See also <A HREF="function.stripcslashes.html" ><B CLASS="function" >stripcslashes()</B ></A >, <A HREF="function.stripslashes.html" ><B CLASS="function" >stripslashes()</B ></A >, <A HREF="function.htmlspecialchars.html" ><B CLASS="function" >htmlspecialchars()</B ></A >, and <A HREF="function.quotemeta.html" ><B CLASS="function" >quotemeta()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="ref.strings.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.addslashes.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >String functions</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.strings.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >addslashes</TD ></TR ></TABLE ></DIV ></BODY ></HTML >