<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >echo</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="crypt" HREF="function.crypt.html"><LINK REL="NEXT" TITLE="explode" HREF="function.explode.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.crypt.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.explode.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.echo" ></A >echo</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN218896" ></A ><P > (PHP 3, PHP 4, PHP 5)</P >echo -- Exibe uma ou mais strings</DIV ><DIV CLASS="refsect1" ><A NAME="AEN218899" ></A ><H2 >Descrição</H2 >void <B CLASS="methodname" >echo</B > ( string arg1 [, string argn...] )<BR ></BR ><P > Exibe todos os parãmetros. </P ><P > <B CLASS="function" >echo()</B > não é uma função atualmente (construtor da linguagem) então não é obrigatório usar parênteses. De fato, se você quer passar mais do que um parâmetro para echo, você não deve fechar os parênteses dentro de parênteses. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN218914" ></A ><P ><B >Exemplo 1. <B CLASS="function" >echo()</B > exemplos</B ></P ><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="#DD0000">"Hello World"</font><font color="#007700">;<br /><br />echo </font><font color="#DD0000">"This spans<br />multiple lines. The newlines will be <br />output as well"</font><font color="#007700">;<br /><br />echo </font><font color="#DD0000">"This spans\nmultiple lines. The newlines will be\noutput as well."</font><font color="#007700">;<br /><br />echo </font><font color="#DD0000">"Escaping characters is done \"Like this\"."</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// You can use variables inside of an echo statement<br /></font><font color="#0000BB">$foo </font><font color="#007700">= </font><font color="#DD0000">"foobar"</font><font color="#007700">;<br /></font><font color="#0000BB">$bar </font><font color="#007700">= </font><font color="#DD0000">"barbaz"</font><font color="#007700">;<br /><br />echo </font><font color="#DD0000">"foo is $foo"</font><font color="#007700">; </font><font color="#FF8000">// foo is foobar<br /><br />// You can also use arrays<br /></font><font color="#0000BB">$bar </font><font color="#007700">= array(</font><font color="#DD0000">"value" </font><font color="#007700">=> </font><font color="#DD0000">"foo"</font><font color="#007700">);<br /><br />echo </font><font color="#DD0000">"this is </font><font color="#007700">{</font><font color="#DD0000">$bar</font><font color="#007700">[</font><font color="#DD0000">'value'</font><font color="#007700">]}</font><font color="#DD0000"> !"</font><font color="#007700">; </font><font color="#FF8000">// this is foo !<br /><br />// Using single quotes will print the variable name, not the value<br /></font><font color="#007700">echo </font><font color="#DD0000">'foo is $foo'</font><font color="#007700">; </font><font color="#FF8000">// foo is $foo<br /><br />// If you are not using any other characters, you can just echo variables<br /></font><font color="#007700">echo </font><font color="#0000BB">$foo</font><font color="#007700">; </font><font color="#FF8000">// foobar<br /></font><font color="#007700">echo </font><font color="#0000BB">$foo</font><font color="#007700">,</font><font color="#0000BB">$bar</font><font color="#007700">; </font><font color="#FF8000">// foobarbarbaz<br /><br />// Some people prefer passing multiple parameters to echo over concatenation.<br /></font><font color="#007700">echo </font><font color="#DD0000">'This '</font><font color="#007700">, </font><font color="#DD0000">'string '</font><font color="#007700">, </font><font color="#DD0000">'was '</font><font color="#007700">, </font><font color="#DD0000">'made '</font><font color="#007700">, </font><font color="#DD0000">'with multiple parameters.'</font><font color="#007700">, </font><font color="#0000BB">chr</font><font color="#007700">(</font><font color="#0000BB">10</font><font color="#007700">);<br />echo </font><font color="#DD0000">'This ' </font><font color="#007700">. </font><font color="#DD0000">'string ' </font><font color="#007700">. </font><font color="#DD0000">'was ' </font><font color="#007700">. </font><font color="#DD0000">'made ' </font><font color="#007700">. </font><font color="#DD0000">'with concatenation.' </font><font color="#007700">. </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /><br />echo <<<END<br /></font><font color="#0000BB">This uses the "here document" syntax to output<br />multiple lines with $variable interpolation. Note<br />that the here document terminator must appear on a<br />line with just a semicolon. no extra whitespace!<br /></font><font color="#007700">END;<br /><br /></font><font color="#FF8000">// Because echo is not a function, following code is invalid. <br /></font><font color="#007700">(</font><font color="#0000BB">$some_var</font><font color="#007700">) ? echo </font><font color="#DD0000">'true' </font><font color="#007700">: echo </font><font color="#DD0000">'false'</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// However, the following examples will work:<br /></font><font color="#007700">(</font><font color="#0000BB">$some_var</font><font color="#007700">) ? print(</font><font color="#DD0000">'true'</font><font color="#007700">): print(</font><font color="#DD0000">'false'</font><font color="#007700">); </font><font color="#FF8000">// print is a function<br /></font><font color="#007700">echo </font><font color="#0000BB">$some_var </font><font color="#007700">? </font><font color="#DD0000">'true'</font><font color="#007700">: </font><font color="#DD0000">'false'</font><font color="#007700">; </font><font color="#FF8000">// changing the statement around<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > <B CLASS="function" >echo()</B > também tem uma sintaxe curta, onde você pode seguir imediatamente a tag de abertura com um sinal de igual. Esta sintaxe curta funciona apenas com a configuração <A HREF="ini.core.html#ini.short-open-tag" >short_open_tag</A > habilitada. <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN218921" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> I have <font color="#0000BB"><?=$foo?></font> foo.</font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > For a short discussion about the differences between <A HREF="function.print.html" ><B CLASS="function" >print()</B ></A > and <B CLASS="function" >echo()</B >, see this FAQTs Knowledge Base Article: <A HREF="http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40" TARGET="_top" >http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40 </A > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B >Este é um construtor de linguagem e não uma função, por isso não é possível chamá-lo através de <A HREF="functions.variable-functions.html" >funções variáveis</A ></P ></BLOCKQUOTE ></DIV ><P > Veja também <A HREF="function.print.html" ><B CLASS="function" >print()</B ></A >, <A HREF="function.printf.html" ><B CLASS="function" >printf()</B ></A >, e <A HREF="function.flush.html" ><B CLASS="function" >flush()</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.crypt.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.explode.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >crypt</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" >explode</TD ></TR ></TABLE ></DIV ></BODY ></HTML >