<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.basic-syntax.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'language.basic-syntax.phpmode.php',
    1 => '从 HTML 中分离',
    2 => '从 HTML 中分离',
  ),
  'up' => 
  array (
    0 => 'language.basic-syntax.php',
    1 => '基本语法',
  ),
  'prev' => 
  array (
    0 => 'language.basic-syntax.phptags.php',
    1 => 'PHP 标签',
  ),
  'next' => 
  array (
    0 => 'language.basic-syntax.instruction-separation.php',
    1 => '指令分隔符',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'language/basic-syntax.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="language.basic-syntax.phpmode" class="sect1">
   <h2 class="title">从 HTML 中分离</h2>
   <p class="para">
    PHP 解析器会忽略一对开始和结束标签之外的内容，这使得 PHP 文件可以具备混合内容。可以使 PHP
    嵌入到 HTML 文档中去，例如创建模板。
   </p>
   <p class="para">
    <div class="example" id="example-1">
     <p><strong>示例 #1 HTML 中嵌入 PHP</strong></p>
     <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000">&lt;p&gt;This is going to be ignored by PHP and displayed by the browser.&lt;/p&gt;<br /><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">echo </span><span style="color: #DD0000">'While this is going to be parsed.'</span><span style="color: #007700">; </span><span style="color: #0000BB">?&gt;<br /></span>&lt;p&gt;This will also be ignored by PHP and displayed by the browser.&lt;/p&gt;</span></code></div>
     </div>

    </div>
   </p>
   <p class="para">
    这将如预期中的运行，因为当 PHP 解释器碰到 ?&gt;
    结束标签时就简单地将其后内容原样输出（除非马上紧接换行 - 见
    <a href="language.basic-syntax.instruction-separation.php" class="link">指令分隔符</a>）直到碰到下一个开始标签；例外是处于条件语句中间时，此时
    PHP 解释器会根据条件判断来决定哪些输出，哪些跳过。见下例。
   </p>
   <p class="para">
   使用条件结构：
    <div class="example" id="example-2">
     <p><strong>示例 #2 使用条件的高级分离术</strong></p>
     <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">if (</span><span style="color: #0000BB">$expression </span><span style="color: #007700">== </span><span style="color: #0000BB">true</span><span style="color: #007700">): </span><span style="color: #0000BB">?&gt;<br /></span>  This will show if the expression is true.<br /><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">else: </span><span style="color: #0000BB">?&gt;<br /></span>  Otherwise this will show.<br /><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">endif; </span><span style="color: #0000BB">?&gt;</span></span></code></div>
     </div>

    </div>
    上例中 PHP 将跳过条件语句未达成的段落，即使该段落位于 PHP 开始和结束标签之外。由于
    PHP 解释器会在条件未达成时直接跳过该段条件语句块，因此 PHP 会根据条件来忽略之。
   </p>
   <p class="para">
    要输出大段文本时，跳出 PHP 解析模式通常比将文本通过
    <span class="function"><a href="function.echo.php" class="function">echo</a></span> 或 <span class="function"><a href="function.print.php" class="function">print</a></span> 输出更有效率。
   </p>
   <p class="para">
    <blockquote class="note"><p><strong class="note">注意</strong>: 
     <p class="para">
      如果 PHP 嵌入到 XML 或 XHTML 中，必须使用标准的 PHP <code class="code">&lt;?php ?&gt;</code> 标签以保持与标准的兼容性。
     </p>
    </p></blockquote>
   </p>
  </div><?php manual_footer($setup); ?>