language/basic-syntax.xml
6b09bb638aa64d1fad5f4a630a8da9a2692ce733
...
...
@@ -19,12 +19,39 @@
19
19
</para>
20
20

21
21
<para>
22
-
PHP also allows for short open tag <literal>&lt;?</literal> (which is
23
-
discouraged since it is only available if enabled using the
24
-
<link linkend="ini.short-open-tag">short_open_tag</link> &php.ini;
25
-
configuration file directive, or if PHP was configured with the
26
-
<option>--enable-short-tags</option> option).
22
+
<example>
23
+
<title>PHP Opening and Closing Tags</title>
24
+
<programlisting role="php">
25
+
<![CDATA[
26
+
1. <?php echo 'if you want to serve PHP code in XHTML or XML documents,
27
+
use these tags'; ?>
28
+

29
+
2. You can use the short echo tag to <?= 'print this string' ?>.
30
+
It's equivalent to <?php echo 'print this string' ?>.
31
+

32
+
3. <? echo 'this code is within short tags, but will only work '.
33
+
'if short_open_tag is enabled'; ?>
34
+
]]>
35
+
</programlisting>
36
+
</example>
27
37
</para>
38
+

39
+
<para>
40
+
Short tags (example three) are available by default but can be disabled
41
+
either via the <link linkend="ini.short-open-tag">short_open_tag</link>
42
+
&php.ini; configuration file directive, or are disabled by default if
43
+
PHP is built with the <option>--disable-short-tags</option> configuration.
44
+
</para>
45
+
<para>
46
+
<note>
47
+
<para>
48
+
As short tags can be disabled it is recommended to only use the normal
49
+
tags (<code>&lt;?php ?&gt;</code> and <code>&lt;?= ?&gt;</code>) to
50
+
maximise compatibility.
51
+
</para>
52
+
</note>
53
+
</para>
54
+

28
55
<para>
29
56
If a file contains only PHP code, it is preferable to omit the PHP closing tag
30
57
at the end of the file. This prevents accidental whitespace or new lines
...
...
@@ -47,6 +74,7 @@ echo "Last statement";
47
74
</informalexample>
48
75
</para>
49
76
</sect1>
77
+

50
78
<sect1 xml:id="language.basic-syntax.phpmode">
51
79
<title>Escaping from HTML</title>
52
80
<para>
...
...
@@ -63,7 +91,7 @@ echo "Last statement";
63
91
</programlisting>
64
92
</informalexample>
65
93
This works as expected, because when the PHP interpreter hits the ?&gt; closing
66
-
tags, it simply starts outputting whatever it finds (except for an
94
+
tags, it simply starts outputting whatever it finds (except for the
67
95
immediately following newline - see
68
96
<link linkend="language.basic-syntax.instruction-separation">instruction separation</link>)
69
97
until it hits another opening tag unless in the middle of a conditional
...
...
@@ -96,51 +124,16 @@ echo "Last statement";
96
124
<function>echo</function> or <function>print</function>.
97
125
</para>
98
126
<para>
99
-
There is also the short echo tag <code>&lt;?= ?&gt;</code>.
100
-
</para>
101
-
<para>
102
-
<note>
103
-
<para>
104
-
Also note that if you are embedding PHP within XML or XHTML
105
-
you will need to use the &lt;?php ?&gt; tags to remain
106
-
compliant with standards.
107
-
</para>
108
-
</note>
109
-
</para>
110
-

111
-
<para>
112
-
<example>
113
-
<title>PHP Opening and Closing Tags</title>
114
-
<programlisting role="php">
115
-
<![CDATA[
116
-
1. <?php echo 'if you want to serve PHP code in XHTML or XML documents,
117
-
use these tags'; ?>
118
-

119
-
2. You can use the short echo tag to <?= 'print this string' ?>.
120
-
It's equivalent to <?php echo 'print this string' ?>.
121
-

122
-
3. <? echo 'this code is within short tags, but will only work '.
123
-
'if short_open_tag is enabled'; ?>
124
-
]]>
125
-
</programlisting>
126
-
</example>
127
-
</para>
128
-
<para>
129
-
Short tags (example three) are available by default but can be disabled
130
-
either via the <link linkend="ini.short-open-tag">short_open_tag</link>
131
-
&php.ini; configuration file directive, or are disabled by default if
132
-
PHP is built with the <option>--disable-short-tags</option> configuration.
133
-
</para>
134
-
<para>
135
127
<note>
136
128
<para>
137
-
As short tags can be disabled it is recommened to only use the normal
138
-
tags (<code>&lt;?php ?&gt;</code> and <code>&lt;?= ?&gt;</code>) to
139
-
maximise compatibility.
129
+
If PHP is embeded within XML or XHTML the normal PHP
130
+
<code>&lt;?php ?&gt;</code> must be used to remain compliant
131
+
with the standards.
140
132
</para>
141
133
</note>
142
134
</para>
143
135
</sect1>
136
+

144
137
<sect1 xml:id="language.basic-syntax.instruction-separation">
145
138
<title>Instruction separation</title>
146
139
<para>
...
...
@@ -150,6 +143,31 @@ echo "Last statement";
150
143
do not need to have a semicolon terminating the last line of a
151
144
PHP block. The closing tag for the block will include the immediately
152
145
trailing newline if one is present.
146
+
</para>
147
+

148
+
<para>
149
+
<example>
150
+
<title>Example showing the closing tag encompassing the trailing newline</title>
151
+
<programlisting role="php">
152
+
<![CDATA[
153
+
<?php echo "Some text"; ?>
154
+
No newline
155
+
<?= "But newline now" ?>
156
+
]]>
157
+
</programlisting>
158
+
&example.outputs;
159
+
<screen>
160
+
<![CDATA[
161
+
Some textNo newline
162
+
But newline now
163
+
]]>
164
+
</screen>
165
+
</example>
166
+
</para>
167
+

168
+
<para>
169
+
Examples of entering and exiting the PHP parser:
170
+

153
171
<informalexample>
154
172
<programlisting role="php">
155
173
<![CDATA[
156
174