-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphptutorial.php
More file actions
3945 lines (905 loc) · 45.6 KB
/
phptutorial.php
File metadata and controls
3945 lines (905 loc) · 45.6 KB
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php include('server.php') ?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<script defer src="https://use.fontawesome.com/releases/v5.0.7/js/all.js"></script>
<link rel="stylesheet" href="styles.css">
<script>
function openSlideMenu(){
document.getElementById('menu').style.width = '250px';
document.getElementById('content').style.marginLeft = '250px';
}
function closeSlideMenu(){
document.getElementById('menu').style.width = '0';
document.getElementById('content').style.marginLeft = '0';
}
</script>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous" />
<title>TANT SCHOOL</title>
<style>
</style>
</head>
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary" style="background-image: linear-gradient(to top, rgba(190, 45, 219, 0.733), rgb(240, 66, 225));">
<a class="navbar-brand" href="index.php">TantSchool</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="index.php">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="courses.php">Courses</a>
</li>
<li class="nav-item">
<a class="nav-link" href="exercises.php">Practice Exercises</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.php">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contactus.php">Contact Us</a>
</li>
</ul>
<?php if (isset($_SESSION['username'])) : ?>
<a href="userprofile.php">
<p style="color: white;">Welcome <strong><?php echo $_SESSION['username']; ?></strong></p></a>
<a href="exercises.php?logout='1'" class="btn btn-info transition-hover btn-lg ml-3">Logout</a>
<?php else: ?>
<form class="form-inline my-2 my-lg-0">
<a href="login.php" class="btn btn-primary transition-hover btn-lg ml-3">Sign In</a>
<a href="register.php" class="btn btn-success transition-hover btn-lg ml-3">Sign Up</a>
</button>
</form>
<?php endif ?>
</div>
</nav>
<div id="content">
<span class="slide">
<a href="#" onclick="openSlideMenu()">
<i class="fas fa-bars"></i>
</a>
</span>
<div id="menu" class="nav">
<a href="#" class="close" onclick="closeSlideMenu()">
<i class="fas fa-times"></i>
</a>
<h4 style="color: white;margin-left:33px;">PHP Tutorials</h4>
<a class="nav-link" href="#intro">PHP Intro</a>
<a class="nav-link" href="#syntax">PHP Syntax</a>
<!-- <a class="nav-link" href="#comments">PHP Comments</a> -->
<a class="nav-link" href="#variables">PHP Variables</a>
<a class="nav-link" href="#echo">PHP Echo/Print</a>
<a class="nav-link" href="#data">PHP Data Types</a>
<a class="nav-link" href="#switch">PHP Switch</a>
<a class="nav-link" href="#ifelse">PHP if...else...elseif</a>
<a class="nav-link" href="#loop">PHP Loop</a>
<a class="nav-link" href="#functions">PHP Function</a>
<a class="nav-link" href="#arrays">PHP Arrays</a>
<a class="nav-link" href="#superglobal">PHP Super globals</a>
<a class="nav-link" href="#regex">PHP RegEx</a>
</div>
</div>
<div class="container">
<div id="intro">
<h1>PHP: Hypertext Preprocessor <span class="color_h1">Introduction</span></h1>
<hr>
<iframe width="90%" height="315" src="https://youtube.com/embed/a_qREkJ78f4" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<br><br>
<h2>What You Should Already Know</h2>
<p>Before you continue you should have a basic understanding of the following:</p>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
<p>If you want to study these subjects first, find the tutorials on our <a href="courses.php">Home page.</a></p>
<h2>What is PHP?</h2>
<ul>
<li>PHP is an acronym for "PHP: Hypertext Preprocessor"</li>
<li>PHP is a widely-used, open source scripting language</li>
<li>PHP scripts are executed on the server</li>
<li>PHP is free to download and use</li>
</ul>
<div style="width:100%;">
<br><br>
<div style="margin-left:2%;">
<strong><p>PHP is an amazing and popular language!</p></strong>
<p>It is powerful enough to be at the core of the
biggest blogging system on the web (WordPress)!</p>
<p>It is deep enough to run the largest social network (Facebook)!</p>
<p>It is also easy enough to be a beginner's first server side language!</p>
<br><br>
</div>
</div>
<br>
<h2>What is PHP File?</h2>
<ul>
<li>PHP files can contain text, HTML, CSS, JavaScript, and PHP code</li>
<li>PHP code is executed on the server, and the result is returned to the browser as plain HTML</li>
<li>PHP files have extension ".php"</li>
</ul>
<h3>What Can PHP Do?</h3>
<ul>
<li>PHP can generate dynamic page content</li>
<li>PHP can create, open, read, write, delete, and close files on the server</li>
<li>PHP can collect form data</li>
<li>PHP can send and receive cookies</li>
<li>PHP can add, delete, modify data in your database</li>
<li>PHP can be used to control user-access</li>
<li>PHP can encrypt data</li>
<li></li>
<li></li>
</ul>
<p>With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies.
You can also output any text, such as XHTML and XML.</p>
<h3>Why PHP?</h3>
<ul>
<li>PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)</li>
<li>PHP is compatible with almost all servers used today (Apache, IIS, etc.)</li>
<li>PHP supports a wide range of databases</li>
<li>PHP is easy to learn and runs efficiently on the server side</li>
</ul>
<h3>What's New In PHP 7</h3>
<ul>
<li>PHP 7 is much faster than the previous popular stable release (PHP 5.6)</li>
<li>PHP 7 has improved Error Handling</li>
<li>PHP 7 supports stricter Type Declarations for function arguments</li>
<li>PHP 7 supports new operators (like the spaceship operator: <=> )</li>
</ul>
<hr>
</div>
<div id="syntax">
<h1>PHP <span class="color_h1">Syntax</span></h1>
<hr>
<iframe width="90%" height="315" src="https://www.youtube.com/embed/eLBDf7U4DfQ" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<hr>
</div>
<div id="indent">
<h1>Basic PHP <span class="color_h1">Syntax</span></h1>
<hr>
<p>A PHP script can be placed anywhere in the document.</p>
<p>A PHP script starts with <?php and ends with ?></p>
<div style="border:1px solid black;width:100%">
<p>
<br>
<?php<br>
// PHP code goes here<br>
?>
</p>
</div>
<p>A PHP file normally contains HTML tags, and some PHP scripting code.</p>
<p>Below, we have an example of a simple PHP file, with a PHP script that uses a
built-in PHP function "echo" to output the text "Hello World!" on a web page:</p>
<div class="w3-example">
<h3>Example</h3>
<div style="background-color:white;">
<br>
<div class="w3-code htmlHigh notranslate">
<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>!DOCTYPE<span class="attributecolor" style="color:red"> html</span><span class="tagcolor" style="color:mediumblue">></span></span><br>
<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>html<span class="tagcolor" style="color:mediumblue">></span></span><br>
<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>body<span class="tagcolor" style="color:mediumblue">></span></span><br><br>
<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>h1<span class="tagcolor" style="color:mediumblue">></span></span>My first PHP page<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>/h1<span class="tagcolor" style="color:mediumblue">></span></span><br><br>
<span class="phpcolor" style="color:black"><span class="phptagcolor" style="color:red"><?php</span><br><span class="phpnumbercolor" style="color:red">
</span> <span class="phpkeywordcolor" style="color:mediumblue">echo</span> <span class="phpstringcolor" style="color:brown">"Hello World!"</span>;<br><span class="phptagcolor" style="color:red">?></span></span><br><br>
<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>/body<span class="tagcolor" style="color:mediumblue">></span></span><br>
<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>/html<span class="tagcolor" style="color:mediumblue">></span></span>
<br><br>
</div>
</div>
<div>
</div>
<br>
<h3>PHP Case Sensitivity</h3>
<p>In PHP, keywords (e.g. if, else, while, echo, etc.), classes,
functions, and user-defined functions are not case-sensitive.</p>
<p>In the example below, all three echo statements below are equal and legal:</p>
<div class="w3-example">
<h3>Example</h3>
<div style="background-color:white;">
<br>
<div class="w3-code htmlHigh notranslate">
<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>!DOCTYPE<span class="attributecolor" style="color:red"> html</span><span class="tagcolor" style="color:mediumblue">></span></span><br>
<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>html<span class="tagcolor" style="color:mediumblue">></span></span><br>
<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>body<span class="tagcolor" style="color:mediumblue">></span></span><br><br>
<span class="phpcolor" style="color:black"><span class="phptagcolor" style="color:red"><?php</span><br><span class="phpnumbercolor" style="color:red">
</span> <span class="phpkeywordcolor" style="color:mediumblue">ECHO</span> <span class="phpstringcolor" style="color:brown">"Hello World!<br>"</span>;<br><span class="phpkeywordcolor" style="color:mediumblue">echo</span> <span class="phpstringcolor" style="color:brown">"Hello World!<br>"</span>;<br><span class="phpnumbercolor" style="color:red">
</span> <span class="phpkeywordcolor" style="color:mediumblue">EcHo</span> <span class="phpstringcolor" style="color:brown">"Hello World!<br>"</span>;<br><span class="phptagcolor" style="color:red">?></span></span><br><br>
<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>/body<span class="tagcolor" style="color:mediumblue">></span></span><br>
<span class="tagnamecolor" style="color:brown"><span class="tagcolor" style="color:mediumblue"><</span>/html<span class="tagcolor" style="color:mediumblue">></span></span>
<br><br>
</div>
</div>
</div>
<br>
<div style="width:100%;">
<br>
<div style="margin-left:2%;">
<strong><p>NOTE:</p></strong>
<p>However; all variable names are case-sensitive!</p>
<br>
</div>
</div>
<hr>
<div id="variables">
<h1>PHP <span class="color_h1">Variables</span></h1>
<hr>
<iframe width="90%" height="315" src="https://www.youtube.com/embed/L2kwYV_paRE" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<br><br>
<p>Variables are "containers" for storing information.</p>
<hr>
<h2>Creating (Declaring) PHP Variables</h2>
<p>In PHP, a variable starts with the $ sign, followed by the name of the variable:</p>
<div class="w3-example">
<h3>Example</h3>
<div style="background-color:white;">
<br>
<div class="w3-code notranslate htmlHigh">
<span class="phpcolor" style="color:black"><span class="phptagcolor" style="color:red"><?php</span><br>
$txt = <span class="phpstringcolor" style="color:brown">"Hello world!"</span>;<br>
$x = <span class="phpnumbercolor" style="color:red">5</span>;<br>$y = <span class="phpnumbercolor" style="color:red">10.5</span>;<br>
<span class="phptagcolor" style="color:red">?></span></span>
<br><br>
</div>
</div>
</div>
<p>After the execution of the statements above, the variable $txt will
hold the value Hello world!, the variable $x will hold the value 5, and the variable $y will hold the value 10.5.</p>
<strong><p>NOTE:</p></strong>
<li>When you assign a text value to a variable, put quotes around the value.</li>
<li>Unlike other programming languages, PHP has no command for declaring a variable.
It is created the moment you first assign a value to it.</li>
<br>
<div style="width:100%;">
<br>
<div style="margin-left:2%;">
<p>Think of variables as containers for storing data.</p>
<br>
</div>
</div>
<br>
<h3>PHP Variables</h3>
<p>A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume).<br>
Rules for PHP variables:</p>
<ul>
<li>A variable starts with the $ sign, followed by the name of the variable</li>
<li>A variable name must start with a letter or the underscore character</li>
<li>A variable name cannot start with a number</li>
<li>A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )</li>
<li>Variable names are case-sensitive (age, Age and AGE are three different variables)</li>
</ul>
<br>
<div style="width:100%;">
<br>
<div style="margin-left:2%;">
<p>Remember that PHP variable names are case-sensitive!</p>
<br>
</div>
</div>
<br>
<h3>PHP Variables Scope</h3>
In PHP, variables can be declared anywhere in the script.
The scope of a variable is the part of the script where the variable can be referenced/used.
PHP has three different variable scopes:
<li>local</li>
<li>global</li>
<li>static</li>
<br>
<h3>Global Scope</h3>
<br>
A variable declared <strong>outside</strong> a function has a GLOBAL SCOPE and can only be accessed outside a function:
<br>
<br>
<div class="w3-example">
<h3>Example</h3>
<div style="background-color:white;">
<br>
<p>Variable with global scope: </p>
<div class="w3-code htmlHigh notranslate">
<span class="phpcolor" style="color:black"><span class="phptagcolor" style="color:red"><?php</span><br>$x = <span class="phpnumbercolor" style="color:red">5</span>; <span class="commentcolor" style="color:green">// global scope<br></span><br><span class="phpkeywordcolor" style="color:mediumblue">function</span> myTest() {<br> <span class="commentcolor" style="color:green">// using x inside this function will generate an error<br></span> <span class="phpkeywordcolor" style="color:mediumblue">echo</span> <span class="phpstringcolor" style="color:brown">"<p>Variable x inside function is: $x</p>"</span>;<br>} <br>myTest();<br><br><span class="phpkeywordcolor" style="color:mediumblue">echo</span> <span class="phpstringcolor" style="color:brown">"<p>Variable x outside function is: $x</p>"</span>;<br><span class="phptagcolor" style="color:red">?></span></span>
<br><br>
</div>
</div>
</div>
<br>
<h3>Local Scope</h3>
<br>
A variable declared <strong>within</strong> a function has a LOCAL SCOPE and can only be accessed outside a function:
<br>
<br>
<div class="w3-example">
<h3>Example</h3>
<div style="background-color:white;">
<br>
<p>Variable with local scope: </p>
<div class="w3-code htmlHigh notranslate">
<span class="phpcolor" style="color:black"><span class="phptagcolor" style="color:red"><?php</span><br>$x = <span class="phpnumbercolor" style="color:red">5</span>; <span class="commentcolor" style="color:green">// global scope<br></span><br><span class="phpkeywordcolor" style="color:mediumblue">function</span> myTest() {<br> <span class="commentcolor" style="color:green">// using x inside this function will generate an error<br></span> <span class="phpkeywordcolor" style="color:mediumblue">echo</span> <span class="phpstringcolor" style="color:brown">"<p>Variable x inside function is: $x</p>"</span>;<br>} <br>myTest();<br><br><span class="phpkeywordcolor" style="color:mediumblue">echo</span> <span class="phpstringcolor" style="color:brown">"<p>Variable x outside function is: $x</p>"</span>;<br><span class="phptagcolor" style="color:red">?></span></span>
<br><br>
</div>
</div>
</div>
<br>
<h3>Static Keyword</h3>
<br>
Normally, when a function is completed/executed, all of its variables are deleted.
However, sometimes we want a local variable NOT to be deleted. We need it for a further job.
<br>
To do this, use the static keyword when you first declare the variable:
<br>
<br>
<div class="w3-example">
<h3>Example</h3>
<div style="background-color:white;">
<br>
<div class="w3-code htmlHigh notranslate">
<span class="phpcolor" style="color:black"><span class="phptagcolor" style="color:red"><?php</span><br><span class="phpkeywordcolor" style="color:mediumblue">function</span> myTest()<span class="phpnumbercolor" style="color:red">
</span>{<br><span class="phpnumbercolor" style="color:red">
</span> <span class="phpkeywordcolor" style="color:mediumblue">static</span> $x = <span class="phpnumbercolor" style="color:red">0</span>;<br><span class="phpnumbercolor" style="color:red">
</span> <span class="phpkeywordcolor" style="color:mediumblue">echo</span> $x;<br><span class="phpnumbercolor" style="color:red">
</span> $x++;<br><span class="phpnumbercolor" style="color:red">
</span>}<br><br>
myTest();<br>
myTest();<br>
myTest();<br><span class="phptagcolor" style="color:red">?></span></span>
<br><br>
</div>
</div>
</div>
<hr>
<div id="echo">
<h1>PHP <span class="color_h1">Echo / Print Statement</span></h1>
<hr>
<iframe width="90%" height="315" src="https://www.youtube.com/embed/V9c2M7c5xqU" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<br><br>
<p>With PHP, there are two basic ways to get output: echo and print.
<br>
In this tutorial we use echo or print in almost every example.
<br>So, this chapter contains a little more info about those two output statements.</p>
<h3>The PHP echo Statement</h3>
<p>The echo statement can be used with or without parentheses: echo or echo().
<br>The following example shows how to output text with the echo command (notice that the text can contain HTML markup):</p>
<div class="w3-example">
<h3>Example</h3>
<div style="background-color:white;">
<br>
<div class="w3-code htmlHigh notranslate">
<span class="phpcolor" style="color:black"><span class="phptagcolor" style="color:red"><?php</span><br><span class="phpnumbercolor" style="color:red">
</span> <span class="phpkeywordcolor" style="color:mediumblue">echo</span> <span class="phpstringcolor" style="color:brown">"<h2>PHP is Fun!</h2>"</span>;<br><span class="phpnumbercolor" style="color:red">
</span> <span class="phpkeywordcolor" style="color:mediumblue">echo</span> <span class="phpstringcolor" style="color:brown">"Hello world!<br>"</span>;<br><span class="phpkeywordcolor" style="color:mediumblue">echo</span> <span class="phpstringcolor" style="color:brown">"I'm about to learn PHP!<br>"</span>;<br><span class="phpnumbercolor" style="color:red">
</span> <span class="phpkeywordcolor" style="color:mediumblue">echo</span> <span class="phpstringcolor" style="color:brown">"This "</span>, <span class="phpstringcolor" style="color:brown">"string "</span>, <span class="phpstringcolor" style="color:brown">"was "</span>, <span class="phpstringcolor" style="color:brown">"made "</span>, <span class="phpstringcolor" style="color:brown">"with multiple parameters."</span>;<br>
<span class="phptagcolor" style="color:red">?></span></span>
<br><br>
</div>
</div>
</div>
<br>
<h3>The PHP print Statement</h3>
<p>The print statement can be used with or without parentheses: print or ptint().
<br>The following example shows how to output text with the print command (notice that the text can contain HTML markup):</p>
<div class="w3-example">
<h3>Example</h3>
<div style="background-color:white;">
<br>
<div class="w3-code htmlHigh notranslate">
<span class="phpcolor" style="color:black"><span class="phptagcolor" style="color:red"><?php</span><br><span class="phpnumbercolor" style="color:red">
</span> <span class="phpkeywordcolor" style="color:mediumblue">print</span> <span class="phpstringcolor" style="color:brown">"<h2>PHP is Fun!</h2>"</span>;<br><span class="phpnumbercolor" style="color:red">
</span> <span class="phpkeywordcolor" style="color:mediumblue">print</span> <span class="phpstringcolor" style="color:brown">"Hello world!<br>"</span>;<br><span class="phpkeywordcolor" style="color:mediumblue">print</span> <span class="phpstringcolor" style="color:brown">"I'm about to learn PHP!"</span>;<br>
<span class="phptagcolor" style="color:red">?></span></span>
<br><br>
</div>
</div>
</div>
</div>
<div>
<hr>
<div id="data">
<h1>PHP <span class="color_h1">Data Types</span></h1>
<hr>
<iframe width="90%" height="315" src="https://www.youtube.com/embed/oXX2SJKijig" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<br>
<h2>PHP Built-in Data Types</h2>
<p>Variables can store data of different types, and different data types can do different things.
<br>
PHP supports the following data types:</p>
<ul>
<li>String</li>
<li>Integer</li>
<li>Float</li>
<li>Boolean</li>
<li>Array</li>
<li>Object</li>
<li>Null</li>
<li>Resource</li>
</ul>
<h3>PHP String</h3>
<p>A string is a sequence of characters, like "Hello world!".
<br>
A string can be any text inside quotes. You can use single or double quotes:</p>
<div class="w3-example">
<h3>Example</h3>
<div style="background-color:white;">
<br>
<div class="w3-code htmlHigh notranslate">
<span class="phpcolor" style="color:black"><span class="phptagcolor" style="color:red"><?php</span> <br>$x =
<span class="phpstringcolor" style="color:brown">"Hello world!"</span>;<br>$y = <span class="phpstringcolor"
style="color:brown">'Hello world!'</span>;<br><br><span class="phpkeywordcolor" style="color:mediumblue">echo
</span> $x;<br><span class="phpkeywordcolor" style="color:mediumblue">echo</span> <span class="phpstringcolor"
style="color:brown">"<br>"</span>; <br><span class="phpkeywordcolor" style="color:mediumblue">echo</span>
$y;<br><span class="phptagcolor" style="color:red">?></span></span> </div>
<br><br>
</div>
</div>
</div>
<br>
<h3>PHP Integer</h3>
<p>A string is a sequence of characters, like "Hello world!".
<br>