<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >注释</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="基本语法" HREF="language.basic-syntax.html"><LINK REL="PREVIOUS" TITLE="指令分隔符" HREF="language.basic-syntax.instruction-separation.html"><LINK REL="NEXT" TITLE="类型" HREF="language.types.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="sect1" 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="language.basic-syntax.instruction-separation.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >章 10. 基本语法</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="language.types.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="language.basic-syntax.comments" >注释</A ></H1 ><P > PHP 支持 C,C++ 和 Unix Shell 风格(Perl 风格)的注释。例如: <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN2688" ></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="#DD0000">"This is a test"</font><font color="#007700">; </font><font color="#FF8000">// This is a one-line c++ style comment<br /> /* This is a multi line comment<br /> yet another line of comment */<br /> </font><font color="#007700">echo </font><font color="#DD0000">"This is yet another test"</font><font color="#007700">;<br /> echo </font><font color="#DD0000">'One Final Test'</font><font color="#007700">; </font><font color="#FF8000"># This is a one-line shell-style comment<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > 单行注释仅仅注释到行末或者当前的 PHP 代码块,视乎哪个首先出现。这意味着在 <TT CLASS="literal" >// ... ?></TT > 或者 <TT CLASS="literal" ># ... ?></TT > 之后的 HTML 代码将被显示出来:?> 跳出了 PHP 模式并返回了 HTML 模式,<TT CLASS="literal" >//</TT > 或 <TT CLASS="literal" >#</TT > 并不能影响到这一点。如果启用了 <A HREF="ini.core.html#ini.asp-tags" >asp_tags</A > 配置选项,其行为和 <TT CLASS="literal" >// %></TT > 或 <TT CLASS="literal" ># %></TT > 相同。不过,<TT CLASS="literal" ></script></TT > 标记在单行注释中不会跳出 PHP 模式。 </P ><P > <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN2700" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <h1>This is an <font color="#0000BB"><?php </font><font color="#FF8000"># echo "simple";</font><font color="#0000BB">?></font> example.</h1><br /><p>The header above will say 'This is an example'.</font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </P ><P > C 风格的注释在碰到第一个 <TT CLASS="literal" >*/</TT > 时结束。要确保不要嵌套 C 风格的注释。试图注释掉一大块代码时很容易出现该错误。 </P ><P > <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN2705" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /> </font><font color="#FF8000">/*<br /> echo "This is a test"; /* This comment will cause a problem */<br /> </font><font color="#007700">*/<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </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="language.basic-syntax.instruction-separation.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="language.types.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >指令分隔符</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="language.basic-syntax.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >类型</TD ></TR ></TABLE ></DIV ></BODY ></HTML >