Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 870

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!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="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"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.crypt.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.explode.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.echo"
></A
>echo</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN224880"
></A
><P
>    (PHP 3, PHP 4, PHP 5)</P
>echo&nbsp;--&nbsp;Output one or more strings</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN224883"
></A
><H2
>Description</H2
>void <B
CLASS="methodname"
>echo</B
> ( string arg1 [, string ...] )<BR
></BR
><P
>&#13;     Outputs all parameters.
    </P
><P
>&#13;     <B
CLASS="function"
>echo()</B
> is not actually a function (it is a
     language construct), so you are not required to use parentheses
     with it. <B
CLASS="function"
>echo()</B
> (unlike some other language
     constructs) does not behave like a function, so it cannot
     always be used in the context of a function. Additionally, if you want to
     pass more than one parameter to <B
CLASS="function"
>echo()</B
>, the parameters
     must not be enclosed within parentheses.
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN224900"
></A
><P
><B
>例 1. <B
CLASS="function"
>echo()</B
> examples</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?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">=&gt; </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">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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 &lt;&lt;&lt;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 does not behave like a function, the 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 also a construct, but<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// it behaves like a function, so<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// it may be used in this context.<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">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     <B
CLASS="function"
>echo()</B
> also has a shortcut syntax, where you can
     immediately follow the opening tag with an equals sign. This short syntax
     only works with the <A
HREF="ini.core.html#ini.short-open-tag"
>short_open_tag</A
> configuration setting
     enabled.
     <DIV
CLASS="informalexample"
><P
></P
><A
NAME="AEN224907"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
I have <font color="#0000BB">&lt;?=$foo?&gt;</font> foo.</font>
</code></TD
></TR
></TABLE
><P
></P
></DIV
>
    </P
><P
>&#13;     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
>注意: </B
>由于这是一个语言结构而非函数,因此它无法被<A
HREF="functions.variable-functions.html"
>变量函数</A
>调用。</P
></BLOCKQUOTE
></DIV
><P
>&#13;     See also
     <A
HREF="function.print.html"
><B
CLASS="function"
>print()</B
></A
>,
     <A
HREF="function.printf.html"
><B
CLASS="function"
>printf()</B
></A
>, and
     <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"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.explode.html"
ACCESSKEY="N"
>下一页</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"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>explode</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>