chapters/tutorial.xml
46ffb4b3fa11ea5733de780a8bcc211d8dc3d92b
...
...
@@ -69,13 +69,14 @@
69
69
<info><title>Our first PHP script: <filename>hello.php</filename></title></info>
70
70
<programlisting role="php">
71
71
<![CDATA[
72
+
<!DOCTYPE html>
72
73
<html>
73
-
<head>
74
-
<title>PHP Test</title>
75
-
</head>
76
-
<body>
77
-
<?php echo '<p>Hello World</p>'; ?>
78
-
</body>
74
+
<head>
75
+
<title>PHP Test</title>
76
+
</head>
77
+
<body>
78
+
<?php echo '<p>Hello World</p>'; ?>
79
+
</body>
79
80
</html>
80
81
]]>
81
82
</programlisting>
...
...
@@ -90,13 +91,14 @@
90
91
</simpara>
91
92
<screen role="html">
92
93
<![CDATA[
94
+
<!DOCTYPE html>
93
95
<html>
94
-
<head>
95
-
<title>PHP Test</title>
96
-
</head>
97
-
<body>
98
-
<p>Hello World</p>
99
-
</body>
96
+
<head>
97
+
<title>PHP Test</title>
98
+
</head>
99
+
<body>
100
+
<p>Hello World</p>
101
+
</body>
100
102
</html>
101
103
]]>
102
104
</screen>
...
...
@@ -174,20 +176,6 @@
174
176
</para>
175
177
</note>
176
178
177
-
<note>
178
-
<info><title>A Note on Windows Notepad</title></info>
179
-
<para>
180
-
If you are writing your PHP scripts using Windows Notepad, you will need
181
-
to ensure that your files are saved with the <filename>.php</filename> extension.
182
-
(Notepad adds a <filename>.txt</filename> extension to files automatically unless
183
-
you take one of the following steps to prevent it.) When you save the file and
184
-
are prompted to provide a name for the file, place the filename in quotes
185
-
(i.e. "<filename>hello.php</filename>"). Alternatively, you can click on the
186
-
'Text Documents' drop-down menu in the 'Save' dialog box and change the setting
187
-
to "All Files". You can then enter your filename without quotes.
188
-
</para>
189
-
</note>
190
-
191
179
<para>
192
180
Now that you have successfully created a working PHP script, it is
193
181
time to create the most famous PHP script! Make a call to the
...
...
@@ -246,14 +234,16 @@ echo $_SERVER['HTTP_USER_AGENT'];
246
234
A sample output of this script may be:
247
235
</para>
248
236
<screen role="html">
249
-
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
237
+
<![CDATA[
238
+
Mozilla/5.0 (Linux) Firefox/112.0
239
+
]]>
250
240
</screen>
251
241
</example>
252
242
</para>
253
243
<para>
254
244
There are many <link linkend="language.types">types</link> of
255
-
variables available in PHP. In the above example we printed
256
-
an <link linkend="language.types.array">Array</link> element.
245
+
variables available in PHP. In the above example we printed an element
246
+
from an <link linkend="language.types.array">Array</link> variable.
257
247
Arrays can be very useful.
258
248
</para>
259
249
<para>
...
...
@@ -267,7 +257,7 @@ Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
267
257
<para>
268
258
You can put multiple PHP statements inside a PHP tag and create
269
259
little blocks of code that do more than just a single echo.
270
-
For example, if you want to check for Internet Explorer you
260
+
For example, if you want to check for Firefox you
271
261
can do this:
272
262
</para>
273
263
<para>
...
...
@@ -277,8 +267,8 @@ Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
277
267
<programlisting role="php">
278
268
<![CDATA[
279
269
<?php
280
-
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
281
-
echo 'You are using Internet Explorer.<br />';
270
+
if (str_contains($_SERVER['HTTP_USER_AGENT'], 'Firefox')) {
271
+
echo 'You are using Firefox.';
282
272
}
283
273
?>
284
274
]]>
...
...
@@ -288,7 +278,7 @@ if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
288
278
</para>
289
279
<screen role="html">
290
280
<![CDATA[
291
-
You are using Internet Explorer.<br />
281
+
You are using Firefox.
292
282
]]>
293
283
</screen>
294
284
</example>
...
...
@@ -303,14 +293,13 @@ You are using Internet Explorer.<br />
303
293
Reference</link> part of the manual.
304
294
</para>
305
295
<para>
306
-
The second concept we introduced was the <function>strpos</function>
307
-
function call. <function>strpos</function> is a function built into
308
-
PHP which searches a string for another string. In this case we are
309
-
looking for <literal>'MSIE'</literal> (so-called needle) inside
296
+
The second concept we introduced was the <function>str_contains</function>
297
+
function call. <function>str_contains</function> is a function built into
298
+
PHP which determines if a given string contains another string. In this case we are
299
+
looking for <literal>'Firefox'</literal> (so-called needle) inside
310
300
<varname>$_SERVER['HTTP_USER_AGENT']</varname> (so-called haystack). If
311
-
the needle is found inside the haystack, the function returns the position
312
-
of the needle relative to the start of the haystack. Otherwise, it
313
-
returns &false;. If it does not return &false;, the <link
301
+
the needle is found inside the haystack, the function returns true. Otherwise, it
302
+
returns &false;. If it returns &true;, the <link
314
303
linkend="control-structures.if">if</link> expression evaluates to &true;
315
304
and the code within its {braces} is executed. Otherwise, the code is not
316
305
run. Feel free to create similar examples,
...
...
@@ -333,15 +322,15 @@ You are using Internet Explorer.<br />
333
322
<programlisting role="php">
334
323
<![CDATA[
335
324
<?php
336
-
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
325
+
if (str_contains($_SERVER['HTTP_USER_AGENT'], 'Firefox')) {
337
326
?>
338
-
<h3>strpos() must have returned non-false</h3>
339
-
<p>You are using Internet Explorer</p>
327
+
<h3>str_contains() returned true</h3>
328
+
<p>You are using Firefox</p>
340
329
<?php
341
330
} else {
342
331
?>
343
-
<h3>strpos() must have returned false</h3>
344
-
<p>You are not using Internet Explorer</p>
332
+
<h3>str_contains() returned false</h3>
333
+
<p>You are not using Firefox</p>
345
334
<?php
346
335
}
347
336
?>
...
...
@@ -352,8 +341,8 @@ if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
352
341
</para>
353
342
<screen role="html">
354
343
<![CDATA[
355
-
<h3>strpos() must have returned non-false</h3>
356
-
<p>You are using Internet Explorer</p>
344
+
<h3>str_contains() returned true</h3>
345
+
<p>You are using Firefox</p>
357
346
]]>
358
347
</screen>
359
348
</example>
...
...
@@ -363,8 +352,8 @@ if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
363
352
of PHP mode and just sent straight HTML. The important and powerful point
364
353
to note here is that the logical flow of the script remains intact. Only
365
354
one of the HTML blocks will end up getting sent to the viewer depending on
366
-
the result of <function>strpos</function>. In other words, it depends on
367
-
whether the string <literal>MSIE</literal> was found or not.
355
+
the result of <function>str_contains</function>. In other words, it depends on
356
+
whether the string <literal>Firefox</literal> was found or not.
368
357
</para>
369
358
</section>
370
359
...
...
@@ -385,9 +374,13 @@ if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
385
374
<programlisting role="html">
386
375
<![CDATA[
387
376
<form action="action.php" method="post">
388
-
<p>Your name: <input type="text" name="name" /></p>
389
-
<p>Your age: <input type="text" name="age" /></p>
390
-
<p><input type="submit" /></p>
377
+
<label for="name">Your name:</label>
378
+
<input name="name" id="name" type="text">
379
+

380
+
<label for="age">Your age:</label>
381
+
<input name="age" id="age" type="number">
382
+

383
+
<button type="submit">Submit</button>
391
384
</form>
392
385
]]>
393
386
</programlisting>
394
387