⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 language.basic-syntax.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Basic syntax</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="langref.html">Language Reference</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.basic-syntax.instruction-separation.html">Instruction separation</a></div> <div class="up"><a href="langref.html">Language Reference</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div>  <h1>Basic syntax</h1><h2>Table of Contents</h2><ul class="chunklist chunklist_chapter"><li><a href="language.basic-syntax.instruction-separation.html">Instruction separation</a></li><li><a href="language.basic-syntax.comments.html">Comments</a></li></ul>  <div id="language.basic-syntax.phpmode" class="sect1">   <h2 class="title">Escaping from HTML</h2>   <p class="para">    When PHP parses a file, it looks for opening and closing tags,     which tell PHP to start and stop interpreting the code between     them. Parsing in this manner allows php to be embedded in all     sorts of different documents, as everything outside of a pair     of opening and closing tags is ignored by the PHP parser.     Most of the time you will see php embedded in HTML documents,     as in this example.    <div class="informalexample">     <div class="example-contents"><div class="phpcode"><code><span style="color: #000000">&lt;p&gt;This&nbsp;is&nbsp;going&nbsp;to&nbsp;be&nbsp;ignored.&lt;/p&gt;<br /><span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'While&nbsp;this&nbsp;is&nbsp;going&nbsp;to&nbsp;be&nbsp;parsed.'</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">?&gt;<br /></span>&lt;p&gt;This&nbsp;will&nbsp;also&nbsp;be&nbsp;ignored.&lt;/p&gt;</span></code></div>     </div>    </div>   </p>   <p class="para">    You can also use more advanced structures:    <div class="example">     <p><b>Example #1 Advanced escaping</b></p>     <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$expression</span><span style="color: #007700">)&nbsp;{&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">?&gt;<br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;strong&gt;This&nbsp;is&nbsp;true.&lt;/strong&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;<br /></span><span style="color: #007700">}&nbsp;else&nbsp;{&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">?&gt;<br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&lt;strong&gt;This&nbsp;is&nbsp;false.&lt;/strong&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>     </div>    </div>    This works as expected, because when PHP hits the ?&gt; closing    tags, it simply starts outputting whatever it finds (except for an     immediately following newline - see     <a href="language.basic-syntax.instruction-separation.html" class="link">instruction separation</a>    ) until it hits    another opening tag. The example given here is contrived, of    course, but for outputting large blocks of text, dropping out of    PHP parsing mode is generally more efficient than sending all of    the text through <a href="function.echo.html" class="function">echo()</a> or    <a href="function.print.html" class="function">print()</a>.   </p>   <p class="para">    There are four different pairs of opening and closing tags     which can be used in php. Two of those, &lt;?php ?&gt; and     &lt;script language=&quot;php&quot;&gt; &lt;/script&gt;, are always available.    The other two are short tags and <span class="productname">ASP</span>     style tags, and can be turned on and off from the <var class="filename">php.ini</var>     configuration file. As such, while some people find short tags     and <span class="productname">ASP</span> style tags convenient, they     are less portable, and generally not recommended.    <blockquote><p><b class="note">Note</b>:            Also note that if you are embedding PHP within XML or XHTML       you will need to use the &lt;?php ?&gt; tags to remain       compliant with standards.     <br />    </p></blockquote>    </p>   <p class="para">    <div class="example">     <p><b>Example #2 PHP Opening and Closing Tags</b></p>     <div class="example-contents"><div class="phpcode"><code><span style="color: #000000">1.&nbsp;&nbsp;<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'if&nbsp;you&nbsp;want&nbsp;to&nbsp;serve&nbsp;XHTML&nbsp;or&nbsp;XML&nbsp;documents,&nbsp;do&nbsp;like&nbsp;this'</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">?&gt;<br /></span><br />2.&nbsp;&nbsp;<span style="color: #0000BB">&lt;script&nbsp;language="php"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'some&nbsp;editors&nbsp;(like&nbsp;FrontPage)&nbsp;don\'t<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;like&nbsp;processing&nbsp;instructions'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">&lt;/script&gt;<br /></span><br />3.&nbsp;&nbsp;<span style="color: #0000BB">&lt;?&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'this&nbsp;is&nbsp;the&nbsp;simplest,&nbsp;an&nbsp;SGML&nbsp;processing&nbsp;instruction'</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">?&gt;<br /></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">&lt;?=&nbsp;expression&nbsp;?&gt;</span>&nbsp;This&nbsp;is&nbsp;a&nbsp;shortcut&nbsp;for&nbsp;"<span style="color: #0000BB">&lt;?&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">expression&nbsp;?&gt;</span>"<br /><br />4.&nbsp;&nbsp;&lt;%&nbsp;echo&nbsp;'You&nbsp;may&nbsp;optionally&nbsp;use&nbsp;ASP-style&nbsp;tags';&nbsp;%&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;%=&nbsp;$variable;&nbsp;#&nbsp;This&nbsp;is&nbsp;a&nbsp;shortcut&nbsp;for&nbsp;"&lt;%&nbsp;echo&nbsp;.&nbsp;.&nbsp;."&nbsp;%&gt;</span></code></div>     </div>    </div>   </p>   <p class="para">    While the tags seen in examples one and two are both     always available, example one is the most commonly     used, and recommended, of the two.    </p>   <p class="para">    Short tags (example three) are only available when they are     enabled via the <a href="ini.core.html#ini.short-open-tag" class="link">short_open_tag</a>     <var class="filename">php.ini</var> configuration file directive, or if php was configured     with the <span class="option">--enable-short-tags</span> option.   </p>       <p class="para">    <span class="productname">ASP</span> style tags (example four) are only available when     they are enabled via the <a href="ini.core.html#ini.asp-tags" class="link">asp_tags</a> <var class="filename">php.ini</var>    configuration file directive.   </p>   <p class="para">    <blockquote><p><b class="note">Note</b>:            Using short tags should be avoided when developing applications      or libraries that are meant for redistribution, or deployment on      PHP servers which are not under your control, because short tags      may not be supported on the target server.  For portable,      redistributable code, be sure not to use short tags.     <br />    </p></blockquote>   </p>  </div>     </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="langref.html">Language Reference</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.basic-syntax.instruction-separation.html">Instruction separation</a></div> <div class="up"><a href="langref.html">Language Reference</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -