svn: /phpdoc/en/trunk/language/ basic-syntax.xml
| From: | Karma Dordrak | Date: | Wed, 14 Mar 2012 18:11:04 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/ basic-syntax.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-9886@lists.php.net to get a copy of this message | ||
drak Wed, 14 Mar 2012 18:11:04 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=324247
Log:
Add extra section on PHP tags.
Changed paths:
U phpdoc/en/trunk/language/basic-syntax.xml
Modified: phpdoc/en/trunk/language/basic-syntax.xml
===================================================================
--- phpdoc/en/trunk/language/basic-syntax.xml 2012-03-14 17:31:20 UTC (rev 324246)
+++ phpdoc/en/trunk/language/basic-syntax.xml 2012-03-14 18:11:04 UTC (rev 324247)
@@ -2,22 +2,56 @@
<!-- $Revision$ -->
<chapter xml:id="language.basic-syntax" xmlns="http://docbook.org/ns/docbook">
<title>Basic syntax</title>
- <sect1 xml:id="language.basic-syntax.phpmode">
- <title>Escaping from HTML</title>
+ <sect1 xml:id="language.basic-syntax.phptags">
<para>
When PHP parses a file, it looks for opening and closing tags,
+ which are <literal><?php</literal> and
<literal>?></literal>
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.
+ </para>
+ <para>
+ PHP also allows for short tags <literal><?</literal> and
<literal>?></literal>
+ (which are discouraged because they are only available if enabled with
+ <link linkend="ini.short-open-tag">short_open_tag</link> &php.ini;
configuration
+ file directive, or if PHP was configured with the
<option>--enable-short-tags</option>
+ option.
+ </para>
+ <para>
+ If a file is pure PHP code, it is preferable omit the PHP closing tag at the
+ end of the file. This prevents accidental whitespace or new lines after 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.
<informalexample>
<programlisting role="php">
<![CDATA[
-<p>This is going to be ignored.</p>
+<?php
+echo "Hello world";
+
+// ... more code
+
+echo "Last statement";
+
+// the script ends here with no closing ?> tag
+]]>
+ </programlisting>
+ </informalexample>
+ </para>
+ </sect1>
+ <sect1 xml:id="language.basic-syntax.phpmode">
+ <title>Escaping from HTML</title>
+ <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.
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
+<p>This is going to be ignored by PHP and displayed by the browser.</p>
<?php echo 'While this is going to be parsed.'; ?>
-<p>This will also be ignored.</p>
+<p>This will also be ignored by PHP and displayed by the browser.</p>
]]>
</programlisting>
</informalexample>