File: lang-syntax.html

package info (click to toggle)
php3 3%3A3.0.18-0potato1.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,736 kB
  • ctags: 11,198
  • sloc: ansic: 108,120; sh: 2,512; php: 2,024; yacc: 1,887; makefile: 1,038; perl: 537; pascal: 238; awk: 90; cpp: 28; sql: 11
file content (367 lines) | stat: -rw-r--r-- 5,712 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<HTML
><HEAD
><TITLE
>Syntax and grammar</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.41"><LINK
REL="HOME"
TITLE="PHP3 Manual"
HREF="manual.html"><LINK
REL="UP"
TITLE="Language Reference"
HREF="langref.html"><LINK
REL="PREVIOUS"
TITLE="Connection  Handling"
HREF="feature-connection-handling.html"><LINK
REL="NEXT"
TITLE="Types"
HREF="types.html"></HEAD
><BODY
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP3 Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="feature-connection-handling.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="types.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="LANG-SYNTAX"
>Chapter 5. Syntax and grammar</A
></H1
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
><A
HREF="lang-syntax.html#BASIC-SYNTAX"
>Basic Syntax</A
></DT
><DT
><A
HREF="types.html"
>Types</A
></DT
><DT
><A
HREF="variables.html"
>Variables</A
></DT
><DT
><A
HREF="constants.html"
>Constants</A
></DT
><DT
><A
HREF="expressions.html"
>Expressions</A
></DT
><DT
><A
HREF="operators.html"
>Operators</A
></DT
><DT
><A
HREF="control-structures.html"
>Control Structures</A
></DT
></DL
></DIV
><P
>    PHP's syntax is borrowed primarily from C.  Java and Perl have
    also influenced the syntax.

  </P
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="BASIC-SYNTAX"
>Basic Syntax</A
></H1
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="BASIC-SYNTAX.PHPMODE"
>Escaping from HTML</A
></H2
><P
>     There are four ways of escaping from HTML and entering "PHP code
     mode":

    </P
><P
>     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="EXAMPLE"
><P
><B
>Example 5-1. Ways of escaping from HTML</B
></P
><PRE
CLASS="PROGRAMLISTING"
>1.  &lt;? echo ("this is the simplest, an SGML processing instruction\n"); ?&#62;
 
2.  &lt;?php echo("if you want to serve XML documents, do like this\n"); ?&#62;

3.  &lt;script language="php"&#62; 
        echo ("some editors (like FrontPage) don't
              like processing instructions");
    &lt;/script&#62;

4.  &lt;% echo ("As of PHP 3.0.4 you may optionally use ASP-style tags"); %&#62;
    &lt;%= $variable; # This is a shortcut for "&lt;%echo .." %&#62;
      </PRE
></DIV
></TD
></TR
></TABLE
>

    </P
><P
>     The first way is only available if short tags have been enabled
     (either by calling <B
CLASS="FUNCTION"
>short_tags()</B
>, they are
     configured on using the short_tags run-time configuration setting,
     or they are enabled using the --enable-short-tags compile-time
     configuration setting.

    </P
><P
>     The fourth way is only available if ASP-style tags have been
     enabled using either the asp_tags configuration setting or the
     --enable-asp-tags compile-time configuration setting.

    </P
><P
>     The closing "bracket" for the block will include the immediately
     trailing newline if one is present.

   </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="BASIC-SYNTAX.INSTRUCTION-SEPARATION"
>Instruction separation</A
></H2
><P
>     Instructions are separated the same as in C or perl - terminate
     each statement with a semicolon.

    </P
><P
>     The closing tag (?&gt;) also implies the end of the statement, so the
     following are equivalent:

     <DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>&lt;?php
    echo "This is a test";
?&#62;

&lt;?php echo "This is a test" ?&#62;
      </PRE
><P
></P
></DIV
>

   </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="BASIC-SYNTAX.COMMENTS"
>Comments</A
></H2
><P
>     PHP supports 'C', 'C++' and Unix shell-style comments. For example:

    <DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>&lt;?php
    echo "This is a test"; // This is a one-line c++ style comment
    /* This is a multi line comment
       yet another line of comment */
    echo "This is yet another test";
    echo "One Final Test"; # This is shell-style style comment
?&#62;
     </PRE
><P
></P
></DIV
>

    </P
><P
>     The "one-line" comment styles actually only comment to the
     end of the line or the current block of PHP code, whichever
     comes first.
    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>&lt;h1&#62;This is an &lt;?# echo "simple";?&#62; example.&lt;/h1&#62;
&lt;p&#62;The header above will say 'This is an example'.</PRE
><P
></P
></DIV
><P
>     You should be careful not to nest 'C' style comments, which can
     happen when commenting out large blocks.

    </P
><DIV
CLASS="INFORMALEXAMPLE"
><P
></P
><PRE
CLASS="PROGRAMLISTING"
>&lt;?php
 /* 
    echo "This is a test"; /* This comment will cause a problem */
 */
?&#62;
    </PRE
><P
></P
></DIV
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="feature-connection-handling.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="manual.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="types.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Connection  Handling</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="langref.html"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Types</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>