<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >addcslashes</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="String" HREF="ref.strings.html"><LINK REL="PREVIOUS" TITLE="String" HREF="ref.strings.html"><LINK REL="NEXT" TITLE="addslashes" HREF="function.addslashes.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></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" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="ref.strings.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.addslashes.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.addcslashes" ></A >addcslashes</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN218540" ></A ><P > (PHP 4, PHP 5)</P >addcslashes -- String entre aspas com barras no estilo C </DIV ><DIV CLASS="refsect1" ><A NAME="AEN218543" ></A ><H2 >Descrição</H2 >string <B CLASS="methodname" >addcslashes</B > ( string str, string charlist )<BR ></BR ><P > Retorna uma string com barras invertidas antes dos caracteres que estão listados no parâmetro <CODE CLASS="parameter" >charlist</CODE >. Ela escapa <TT CLASS="literal" >\n</TT >, <TT CLASS="literal" >\r</TT > etc. Como no estilo C, caracteres no código ASCII menores que 32 e maiores que 126 são convertidos para representação octadecimal. </P ><P > Tome cuidado se você escolher escapar caracteres 0, a, b, f, n, r, t e v. Eles serão convertidos para \0, \a, \b, \f, \n, \r, \t e \v. No PHP \0 (<TT CLASS="constant" ><B >NULL</B ></TT >), \r (sinal de retorno), \n (novalinha) e \t (tab) são seqüencias de escape predefinidas, enquanto em C todas essas são seqüencias de escape predefinidas. </P ><P > <CODE CLASS="parameter" >charlist</CODE > como "\0..\37", que que escaparia todos os caracteres em código ASCII entre 0 e 37. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN218562" ></A ><P ><B >Exemplo 1. <B CLASS="function" >addcslashes()</B > exemplo</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$escaped </font><font color="#007700">= </font><font color="#0000BB">addcslashes</font><font color="#007700">(</font><font color="#0000BB">$not_escaped</font><font color="#007700">, </font><font color="#DD0000">"\0..\37!@\177..\377"</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > Quando você define uma seqüencia de caracteres no argumento charlist certifique-se que você sabe quais os caracteres que vêm dentro do intervalo que você definiu. <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN218567" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">echo </font><font color="#0000BB">addcslashes</font><font color="#007700">(</font><font color="#DD0000">'foo[ ]'</font><font color="#007700">, </font><font color="#DD0000">'A..z'</font><font color="#007700">);<br /></font><font color="#FF8000">// output: \f\o\o\[ \]<br />// All upper and lower-case letters will be escaped<br />// ... but so will the [\]^_` and any tabs, line<br />// feeds, carriage returns, etc.<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > Também, se o primeiro caracter no intervalo tem um valor ASCII maior do que o segundo, nenhum intervalo será construído. Apenas os caracteres do começo e do fim serão escapados. Use a função <A HREF="function.ord.html" ><B CLASS="function" >ord()</B ></A > para encontrar o valor ASCII para um caracter. <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN218570" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">echo </font><font color="#0000BB">addcslashes</font><font color="#007700">(</font><font color="#DD0000">"zoo['.']"</font><font color="#007700">, </font><font color="#DD0000">'z..A'</font><font color="#007700">);<br /></font><font color="#FF8000">// output: \zoo['\.']<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > Veja também <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 >, e <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" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.addslashes.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >String</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.strings.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >addslashes</TD ></TR ></TABLE ></DIV ></BODY ></HTML >