<?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.phptags.php',
    1 => 'PHP tags',
    2 => 'PHP tags',
  ),
  'up' => 
  array (
    0 => 'language.basic-syntax.php',
    1 => 'Basic syntax',
  ),
  'prev' => 
  array (
    0 => 'language.basic-syntax.php',
    1 => 'Basic syntax',
  ),
  'next' => 
  array (
    0 => 'language.basic-syntax.phpmode.php',
    1 => 'Escaping from HTML',
  ),
  '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.phptags" class="sect1">
   <h2 class="title">PHP tags</h2>
   <p class="para">
    When PHP processes a file, it recognizes the opening and closing
    tags, <code class="literal">&lt;?php</code> and <code class="literal">?&gt;</code>, to
    define the boundaries of PHP code execution. Content outside these
    tags is ignored by the PHP parser, allowing PHP to seamlessly embed
    in various document types.
   </p>

   <p class="para">
    A whitespace character (space, tab, or newline) must follow
    <code class="literal">&lt;?php</code> to ensure proper token separation.
    Omitting this whitespace will result in a syntax error.
   </p>

   <p class="para">
    PHP also includes the short echo tag <code class="literal">&lt;?=</code>,
    which is shorthand for <code class="code">&lt;?php echo</code>.
   </p>
   <p class="para">
    <div class="example" id="example-1">
     <p><strong>Example #1 PHP Opening and Closing Tags</strong></p>
     <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000">1.  <span style="color: #0000BB">&lt;?php </span><span style="color: #007700">echo </span><span style="color: #DD0000">'if you want to serve PHP code in XHTML or XML documents,<br />                use these tags'</span><span style="color: #007700">; </span><span style="color: #0000BB">?&gt;<br /></span><br />2.  You can use the short echo tag to <span style="color: #0000BB">&lt;?= </span><span style="color: #DD0000">'print this string' </span><span style="color: #0000BB">?&gt;</span>.<br />    It's equivalent to <span style="color: #0000BB">&lt;?php </span><span style="color: #007700">echo </span><span style="color: #DD0000">'print this string' </span><span style="color: #0000BB">?&gt;</span>.<br /><br />3.  &lt;? echo 'this code is within short tags, but will only work '.<br />            'if short_open_tag is enabled'; ?&gt;</span></code></div>
     </div>

    </div>
   </p>

   <p class="para">
    Short tags (example three) are available by default but can be disabled
    either via the <a href="ini.core.php#ini.short-open-tag" class="link">short_open_tag</a>
    <var class="filename">php.ini</var> configuration file directive, or are disabled by default if
    PHP is built with the <strong class="option unknown">--disable-short-tags</strong> configuration.
   </p>
   <p class="para">
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <p class="para">
      As short tags can be disabled it is recommended to only use the normal
      tags (<code class="code">&lt;?php ?&gt;</code> and <code class="code">&lt;?= ?&gt;</code>) to
      maximise compatibility.
     </p>
    </p></blockquote>
   </p>

   <p class="para">
    If a file ends with PHP code, it is preferable to omit the PHP closing tag
    at the end of the file. This prevents accidental whitespace or new lines
    being added after the PHP closing tag, which may cause unwanted effects
    because PHP will start output buffering when there is no intention from
    the programmer to send any output at that point in the script.
   </p>
   <p class="para">
    <div class="example" id="example-2">
     <p><strong>Example #2 PHP Code Only File</strong></p>
     <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"Hello world\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// ... more code<br /><br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"Last statement\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// the script ends here with no PHP closing tag</span></span></code></div>
     </div>

    </div>
   </p>
  </div><?php manual_footer($setup); ?>