<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>PHP tags</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.basic-syntax.html">Basic syntax</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.basic-syntax.phpmode.html">Escaping from HTML</a></div> <div class="up"><a href="language.basic-syntax.html">Basic syntax</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="language.basic-syntax.phptags" class="sect1"> <h2 class="title">PHP tags</h2> <p class="para"> When PHP parses a file, it looks for opening and closing tags, which are <em><?php</em> and <em>?></em> 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. </p> <p class="para"> PHP also allows for short open tag <em><?</em> (which is discouraged since it is only available if enabled using 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 <strong class="option unknown">--enable-short-tags</strong> option). </p> <p class="para"> If a file is pure 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. <div class="informalexample"> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"Hello world"</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"</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> <p class="para"> <table class="doctable table"> <caption><strong>Changelog</strong></caption> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>7.0.0</td> <td> The ASP tags <code class="code"><%</code>, <code class="code">%></code>, <code class="code"><%=</code>, and the script tag <code class="code"><script language="php"></code> are removed from PHP. </td> </tr> <tr> <td>5.4.0</td> <td> The tag <?= is always available regardless of the short_open_tag ini setting. </td> </tr> </tbody> </table> </p> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.basic-syntax.html">Basic syntax</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.basic-syntax.phpmode.html">Escaping from HTML</a></div> <div class="up"><a href="language.basic-syntax.html">Basic syntax</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>