<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'language.basic-syntax.phpmode.php',
    1 => 'Escaping from HTML',
    2 => 'Escaping from HTML',
  ),
  'up' => 
  array (
    0 => 'language.basic-syntax.php',
    1 => 'Basic syntax',
  ),
  'prev' => 
  array (
    0 => 'language.basic-syntax.phptags.php',
    1 => 'PHP tags',
  ),
  'next' => 
  array (
    0 => 'language.basic-syntax.instruction-separation.php',
    1 => 'Instruction separation',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    '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">Escaping from HTML</h2>
   <p class="para">
    Everything outside of a pair of opening and closing tags is ignored by the
    PHP parser which allows PHP files to have mixed content. This allows PHP
    to be embedded in HTML documents, for example to create templates.
   </p>
   <p class="para">
    <div class="example" id="example-1">
     <p><strong>Example #1 Embedding PHP in HTML</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">
    This works as expected, because when the PHP interpreter hits the ?&gt; closing
    tags, it simply starts outputting whatever it finds (except for the
    immediately following newline - see
    <a href="language.basic-syntax.instruction-separation.php" class="link">instruction separation</a>)
    until it hits another opening tag unless in the middle of a conditional
    statement in which case the interpreter will determine the outcome of the
    conditional before making a decision of what to skip over.
    See the next example.
   </p>
   <p class="para">
    Using structures with conditions
    <div class="example" id="example-2">
     <p><strong>Example #2 Advanced escaping using conditions</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>
    In this example PHP will skip the blocks where the condition is not met, even
    though they are outside of the PHP open/close tags; PHP skips them according
    to the condition since the PHP interpreter will jump over blocks contained
    within a condition that is not met.
   </p>
   <p class="para">
    For outputting large blocks of text, dropping out of PHP parsing mode is
    generally more efficient than sending all of the text through
    <span class="function"><a href="function.echo.php" class="function">echo</a></span> or <span class="function"><a href="function.print.php" class="function">print</a></span>.
   </p>
   <p class="para">
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <p class="para">
      If PHP is embeded within XML or XHTML the normal PHP
      <code class="code">&lt;?php ?&gt;</code> must be used to remain compliant
      with the standards.
     </p>
    </p></blockquote>
   </p>
  </div><?php manual_footer($setup); ?>