<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >trim</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="substr" HREF="function.substr.html"><LINK REL="NEXT" TITLE="ucfirst" HREF="function.ucfirst.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="function.substr.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.ucfirst.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.trim" ></A >trim</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN222075" ></A ><P > (PHP 3, PHP 4, PHP 5)</P >trim -- Retira espaço no ínicio e final de uma string </DIV ><DIV CLASS="refsect1" ><A NAME="AEN222078" ></A ><H2 >Descrição</H2 >string <B CLASS="methodname" >trim</B > ( string str [, string charlist] )<BR ></BR ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > O parâmetro opcional <CODE CLASS="parameter" >charlist</CODE > foi adicionado no PHP 4.1.0 </P ></BLOCKQUOTE ></DIV ><P > Esta função retorna uma string com os espaçoes retirados do ínicio e do final de <CODE CLASS="parameter" >str</CODE >. Sem o segundo parâmetro, <B CLASS="function" >trim()</B > irá retirar estes caracteres <P ></P ><UL ><LI ><P > " " (<ACRONYM CLASS="acronym" >ASCII</ACRONYM > <TT CLASS="literal" >32</TT > (<TT CLASS="literal" >0x20</TT >)), um espaço normal. </P ></LI ><LI ><P > "\t" (<ACRONYM CLASS="acronym" >ASCII</ACRONYM > <TT CLASS="literal" >9</TT > (<TT CLASS="literal" >0x09</TT >)), uma tabulação. </P ></LI ><LI ><P > "\n" (<ACRONYM CLASS="acronym" >ASCII</ACRONYM > <TT CLASS="literal" >10</TT > (<TT CLASS="literal" >0x0A</TT >)), uma linha nova (line feed). </P ></LI ><LI ><P > "\r" (<ACRONYM CLASS="acronym" >ASCII</ACRONYM > <TT CLASS="literal" >13</TT > (<TT CLASS="literal" >0x0D</TT >)), um retono de carro. </P ></LI ><LI ><P > "\0" (<ACRONYM CLASS="acronym" >ASCII</ACRONYM > <TT CLASS="literal" >0</TT > (<TT CLASS="literal" >0x00</TT >)), o byte <TT CLASS="literal" >NULL</TT >. </P ></LI ><LI ><P > "\x0B" (<ACRONYM CLASS="acronym" >ASCII</ACRONYM > <TT CLASS="literal" >11</TT > (<TT CLASS="literal" >0x0B</TT >)), uma tabulação vertical. </P ></LI ></UL > </P ><P > Você também pode especificar quais caracteres você quer retirar, através do parâmetro <CODE CLASS="parameter" >charlist</CODE >. Simplesmente liste todos os caracteres que você quer retirar. Com <TT CLASS="literal" >..</TT > você pode especificar um intervalo de caracteres. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN222130" ></A ><P ><B >Exemplo 1. Exemplo de uso de <B CLASS="function" >trim()</B ></B ></P ><P > <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />$text </font><font color="#007700">= </font><font color="#DD0000">"\t\tThese are a few words :) ... "</font><font color="#007700">;<br /></font><font color="#0000BB">$trimmed </font><font color="#007700">= </font><font color="#0000BB">trim</font><font color="#007700">(</font><font color="#0000BB">$text</font><font color="#007700">);<br /></font><font color="#FF8000">// $trimmed = "These are a few words :) ..."<br /></font><font color="#0000BB">$trimmed </font><font color="#007700">= </font><font color="#0000BB">trim</font><font color="#007700">(</font><font color="#0000BB">$text</font><font color="#007700">,</font><font color="#DD0000">" \t."</font><font color="#007700">);<br /></font><font color="#FF8000">// $trimmed = "These are a few words :)"<br /></font><font color="#0000BB">$clean </font><font color="#007700">= </font><font color="#0000BB">trim</font><font color="#007700">(</font><font color="#0000BB">$binary</font><font color="#007700">,</font><font color="#DD0000">"\0x00..\0x1F"</font><font color="#007700">);<br /></font><font color="#FF8000">// trim the ASCII control characters at the beginning and end of $binary<br />// (from 0 to 31 inclusive)<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE > </P ></DIV ></TD ></TR ></TABLE ><P > Veja também <A HREF="function.ltrim.html" ><B CLASS="function" >ltrim()</B ></A > e <A HREF="function.rtrim.html" ><B CLASS="function" >rtrim()</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="function.substr.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.ucfirst.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >substr</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" >ucfirst</TD ></TR ></TABLE ></DIV ></BODY ></HTML >