-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpcourse.php
More file actions
1429 lines (1377 loc) · 50.1 KB
/
phpcourse.php
File metadata and controls
1429 lines (1377 loc) · 50.1 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
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<style type="text/css">
@import url('https://fonts.googleapis.com/css?family=Josefin+Sans&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
text-decoration: none;
font-family: sans-serif;
}
body{
background-color: #f3f5f9;
}
.wrapper{
position: relative;
margin: 10px;
}
.wrapper .sidebar{
width: 258px;
height: auto;
margin-top: 1px;
padding: 30px 0px;
position: absolute;
background-color: white;
}
.c2{
padding: 15px;
border-bottom: 1px solid #bdb8d7;
border-bottom: 1px solid rgba(0,0,0,0.05);
border-top: 1px solid rgba(255,255,255,0.05);
list-style: none;
}
.c1{
color: black;
display: block;
}
.course{
cursor: pointer;
width: 40px;
height: 40px;
position: relative;
display: inline-block;
margin-left: 240px;
height: auto;
margin-top:-2px;
}
.course i{
font-size: 40px;
}
.dd-content{
display: none;
position: absolute;
padding: 10px 20px;
background-color: white;
width: 200px;
box-shadow: 2px 2px 4px rgba(0,0,0,0.125);
box-sizing: 0 5px 25px rgba(0,0,0,0.1);
transition: 0.5s;
z-index: 1;
}
.course ul li{
list-style: none;
padding: 10px 0;
border-bottom: 1px solid rgba(0,0,0,0.01);
display: flex;
align-items: center;
}
.course ul li i{
max-width: 20px;
margin-right: 10px;
opacity: 0.5s;
transition: 0.5s;
}
.course ul li:hover i{
opacity: 1;
}
.course ul li a{
display: inline-block;
text-decoration: none;
color: #555;
font-weight: 500;
transition: 0.5s;
}
.course ul li:hover a{
color: #ff5d94;
}
.c2:hover{
background-color: lightgrey;
}
.wrapper .sidebar ul li:hover a{
color: #fff;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
text-align: left;
}
.wrapper .Content
{
float: right;
width:1180px;
min-height: 720px;
height:auto;
background-color:white;
margin-right:60px;
margin-top: 1px;
}
.y
{
text-align: center;
margin-top: 20px;
}
.intro
{
padding:10px;
display: block;
}
.intro p,h3{
margin-left: 10px;
padding: 16px;
font-size: 19px;
}
.syntax,.variables,.eprint,.dtypes,.deci,.loops{
display: none;
}
.syntax p,h2{
margin-left: 10px;
padding: 16px;
font-size: 19px;
}
.variables p,h2{
margin-left: 10px;
padding: 16px;
font-size: 19px;
}
.eprint p,h2{
margin-left: 10px;
padding: 16px;
font-size: 19px;
}
.dtypes p,h2{
margin-left: 10px;
padding: 16px;
font-size: 19px;
}
.deci p,h2{
margin-left: 10px;
padding: 16px;
font-size: 19px;
}
.loops p,h2{
margin-left: 10px;
padding: 16px;
font-size: 19px;
}
.z
{
width: 100%;
padding-top: 20px;
height: 80px;
outline: none;
top: 0;
background-color: white;
}
.left
{
float: left;
width: 140px;
margin-left: 10px;
}
.g
{
float: right;
margin-right: 60px;
margin-bottom: 25px;
margin-top: -8px;
}
.x71
{
background-color:rgb(153, 204, 255);
color: white;
padding: 8px 18px;
margin: 8px 0;
border: none;
cursor: pointer;
width: auto;
border-radius: 2px;
}
.x71:hover
{
opacity: 0.8;
}
.dropdown{
float: right;
cursor: pointer;
width: 40px;
height: 40px;
position: relative;
display: inline-block;
margin-right: 240px;
height: auto;
}
.dropdown i{
font-size: 40px;
}
.dropdown-content {
display: none;
position: absolute;
top: 50px;
padding: 10px 20px;
background-color: lightgrey;
width: 200px;
box-sizing: 0 5px 25px rgba(0,0,0,0.1);
transition: 0.5s;
z-index: 1;
border-radius:15px;
}
.dropdown .dropdown-content::before{
content: '';
position: absolute;
top: -5px;
right: 160px;
width: 20px;
height: 20px;
transform: rotate(45deg);
background-color: lightgrey;
}
.dropdown ul li{
list-style: none;
padding: 10px 0;
border-top: 1px solid rgba(0,0,0,0.1);
display: flex;
align-items: center;
}
.dropdown ul li i{
max-width: 20px;
margin-right: 10px;
opacity: 0.5s;
transition: 0.5s;
}
.dropdown ul li:hover i{
opacity: 1;
}
.dropdown ul li a{
display: inline-block;
text-decoration: none;
color: #555;
font-weight: 500;
transition: 0.5s;
}
.dropdown ul li:hover a{
color: #ff5d94;
}
.show {display: block;}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
padding-top: 60px;
}
.modal-content {
background-color: #fefefe;
margin: 5% auto 15% auto; /* 5% from the top, 15% from the bottom and centered */
border: 1px solid #888;
width: 30%;
height:auto; /* Could be more or less, depending on screen size */
}
.container {
padding: 16px;
}
span.psw {
float: right;
padding-top: 16px;
}
.r1,.r2
{
width:100%;
padding:10px 15px;
margin:5px 0px;
border: 1px solid lightgrey;
outline: none;
border-radius: 2px;
font-size: 17px;
}
::placeholder
{
text-align: center;
}
/* The Close Button (x) */
.close {
position: absolute;
right: 30px;
top: 0;
color: #000;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: red;
cursor: pointer;
}
.submit-btn
{
background-color:#4CAF50;
color: white;
width: 100%;
padding: 10px 30px;
display: block;
outline: none;
margin:auto;
border:none;
cursor: pointer;
font-size: 20px;
}
a
{
text-decoration: none;
}
.slide-controls
{
width:100%;
margin: 35px auto;
position: relative;
box-shadow: 0 0 20px 9px #ff61241f;
}
.toggle-btn
{
text-align: center;
padding: 10px 45px;
cursor: pointer;
background: transparent;
border:0;
outline: none;
position: relative;
font-size: 20px;
}
#btn
{
text-align: center;
position: absolute;
width:50%;
height: 100%;
background: linear-gradient(to right,lightgrey,lightgrey);
transition: .5s;
}
.v
{
text-align: center;
color: white;
padding-top: 200px;
font-size: 45px;
}
.footer
{
padding:50px;
color: #fff;
background-color: #011c39;
}
#login
{
left: 50%;
}
.footer p{
text-align: center;
}
.footer a{
text-decoration: none;
}
.footer-bottom{
text-align: center;
color: #999;
margin-bottom:-30px;
}
.socials a{
background: #364a62;
width: 40px;
height: 40px;
display: inline-block;
}
.socials a i{
color: #e7f2f4;
padding: 10px 12px;
font-size: 20px;
}
.imgcontainer {
position: relative;
}
.animate {
-webkit-animation: animatezoom 0.6s;
animation: animatezoom 0.6s
}
@-webkit-keyframes animatezoom {
from {-webkit-transform: scale(0)}
to {-webkit-transform: scale(1)}
}
@keyframes animatezoom {
from {transform: scale(0)}
to {transform: scale(1)}
}
/* Change styles for span and cancel button on extra small screens */
@media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
img.avatar {
width: 40%;
border-radius: 50%;
}
</style>
<body>
<div class="z">
<div class="left">
<a href="newproject.php"><img src="https://www.simplilearn.com/ice9/new_logo.svgz" style="width: 140px;margin-left: 10px;cursor: pointer;">
</div></a>
<div class="course">
<input type="button" onclick="mycourse()" class="x71" value="Courses" name="">
<ul id='myDrop' class='dd-content'>
<li><a href='coursesection.php'>C++</a></li>
<li><a href='javacoursepage.php'>Java</a></li>
<li><a href='sql.php' >Sql</a></li>
<li><a href='phpcourse.php' >Php</a></li>
<li><a href='PythonCourseNew.php' >Python</a></li>
</ul>
</div>
<?php if(!isset($_SESSION['name']))
echo " <div class='g' id='first'>
<button class='x71' onclick='loginform()' style='width:auto;' type='submit'>Login</button>
</div> " ?>
<?php if(isset($_SESSION['name']))
echo " <div class='dropdown' id='third'>
<i onclick='myFunction()' class='fa fa-user-circle-o'></i>
<ul id='myDropdown' class='dropdown-content'>
<li><i class='fa fa-user' style='font-size:15px;'></i> <a href='profilepage.php'>my profile</a></li>
<li><i class='fa fa-edit' style='font-size:15px;'></i> <a href='editprofile.php'>Edit profile</a></li>
<li><i class='fa fa-sign-out' style='font-size:15px;'></i> <a href='newlogout.php' id='second' >Logout</a></li>
</ul>
</div>";?>
</div>
<div id="id01" class="modal">
<div class="modal-content animate">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
</div>
<div class="wrapper1" style="width:70%;height:70%;margin-left: 60px;padding: 30px;border-radius:5px;overflow: hidden;">
<div class="title-text" style="display: flex;width: 200%">
<div class="title login" style="width: 50%;font-size:35px;font-weight: 600;text-align: center">Login Form</div>
</div>
<div class="form-container" style="width: 100%;overflow: hidden;">
<div class="form-inner" style="display: flex;width: 200%;">
<form action="newlogin.php" method="post" class="login" id="login" style="width:50%;">
<div style="height: 50px;width: 90%;margin-top: 20px;padding-top: 2px;padding-bottom: 2px;">
<input type="text" class="r1" placeholder="username or email" name="name" required="">
</div>
<div style="height: 50px;width: 90%;margin-top: 20px;">
<input type="password" class="r2" placeholder="Password" name="password" required="">
</div><br><br>
<div class="pass-link">
<a href="#">Forgot password?</a><br><br>
</div>
<div>
<input type="submit" class="submit-btn" value="Login" onclick="account()">
</div><br>
<div class="signup-link">Not a member? <a href="http://localhost/signup.php">Signup now</a></div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="wrapper">
<div class="sidebar">
<ul>
<li class="c2"><a href="#" class="c1" onclick="intro()">PHP | Introduction</a></li>
<li class="c2"><a href="#" class="c1" onclick="syntax()">PHP | Basic Syntax</a></li>
<li class="c2"><a href="#" class="c1" onclick="variables()">PHP | Variables</a></li>
<li class="c2"><a href="#" class="c1" onclick="eprint()">PHP | echo and print</a></li>
<li class="c2"><a href="#" class="c1" onclick="dtypes()">PHP | Data Types</a></li>
<li class="c2"><a href="#" class="c1" onclick="decision()">PHP | Decision Making</a></li>
<li class="c2"><a href="#" class="c1" onclick="loops()">PHP | Loops</a></li>
<li class="c2"><a href="https://docs.google.com/forms/d/e/1FAIpQLSdVLP5yLYqDIb4sO-QYjyDJHCHqlhCDph7fw8sVRp0_jA-jrQ/viewform?usp=sf_link" target="_blank" class="c1">Quiz-Php</a></li>
</ul>
</div>
<div class="Content" style="font-family: sans-serif;">
<div class="intro" id="v">
<h1 class="y">PHP | Introduction</h1>
<img src="https://www.geeksforgeeks.org/wp-content/uploads/php-1-768x256.png" style="margin-left: 190px;margin-top:40px;">
<p>The term PHP is an acronym for PHP: Hypertext Preprocessor. PHP is a server-side scripting language designed specifically for web development.</p>
<ul>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;" >Websites like www.facebook.com, www.yahoo.com are also built on PHP.</li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;">One of the main reason behind this is that PHP can be easily embedded in HTML files and HTML codes can also be written in a PHP file. </li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;">The thing that differentiates PHP with client-side language like HTML is, PHP codes are executed on server whereas HTML codes are directly rendered on the browser. PHP codes are first executed on the server and then the result is returned to the browser.</li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;">The only information that the client or browser knows is the result returned after executing the PHP script on the server and not the actual PHP codes present in the PHP file. Also, PHP files can support other client-side scripting languages like CSS and JavaScript.
</li>
</ul>
<h3>Why should we use PHP?</h3>
<p>PHP can actually do anything related to server-side scripting or more popularly known as the backend of a website. For example, PHP can receive data from forms, generate dynamic page content, can work with databases, create sessions, send and receive cookies, send emails etc. There are also many hash functions available in PHP to encrypt user’s data that makes PHP secure and reliable to be used as a server-side scripting language. So these are some of the abilities of PHP that makes it suitable to be used as server-side scripting language. You will get to know more of these abilities in further tutorials.</p>
<p>
Even if you are not convinced by the above abilities of PHP, there are some more features of PHP. PHP can run on all major operating systems like Windows, Linux, Unix, Mac OS X etc. Almost all of the major servers available today like Apache supports PHP. PHP allows using wide range of databases. And the most important factor is that it is free to use and download and anyone can download PHP from its official source : www.php.net.
</p>
</div>
<div class="syntax" id="syn">
<h1 class="y">PHP | Basic Syntax</h1>
<p>PHP or Hypertext Preprocessor is a widely used open-source general purpose scripting language and can be embedded with HTML. PHP files are saved with “.php” extension. PHP scripts can be written anywhere in the document within PHP tags along with normal HTML.</p>
<h2>PHP Tags or Escaping To PHP</h2>
<p>The mechanism of separating a normal HTML from PHP code is called the mechanism of Escaping To PHP. There are various ways in which this can be done. Few methods are already set by default but in order to use few others like Short-open or ASP-style tags we need to change the configuration of php.ini file. These tags are also used for embedding PHP within HTML.</p>
<h3>Canonical PHP Tags:</h3>
<p>The script starts with <.?php and end with ?> . These tags are also called ‘Canonical PHP tags’. Every PHP command ends with a semi-colon (;). Let’s look at the hello world program in PHP:</p>
<p>Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php<br>
# Here echo command is used to print<br>
echo "Hello, world!";<br>
?><br>
</div><br>
<p>Output: </p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
Hello, world!
</div>
<h2>Comments in PHP</h2>
<p>A comment is something which is ignored and not read or executed by PHP engine or the language as part of a program and is written to make the code more readable and understandable. These are used to help other users and developers to describe the code and what it is trying to do. It can also be used in documenting a set of code or part of a program. You must have noticed this in above sample programs.</p>
<h3>Single Line Comment: </h3>
<p>As the name suggests these are single line or short relevant explanations that one can add in there code. To add this, we need to begin the line with (//) or (#).</p>
<p>Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php<br>
// This is a single line comment <br>
// These cannot be extended to more lines<br>
echo "Hello, world!";<br>
# This is also a single line comment<br>
?><br>
</div><br>
<p>Output: </p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
hello world!!!
</div>
<h2>Case Sensitivity in PHP</h2>
<h3>PHP is insensitive of whitespace.</h3>
<p>This includes all types of spaces that are invisible on the screen including tabs, spaces, and carriage return. Even one space is equal to any numbers of spaces or carriage return. This means that PHP will ignore all the spaces or tabs in a single row or carriage return in multiple rows. Unless a semi-colon is encountered, PHP treats multiple lines as a single command.</p>
<h3>PHP is case-sensitive.</h3>
<p> All the keywords, functions and class names in PHP (while, if, echo etc) are NOT case-sensitive except variables. Only variables with different cases are treated differently.</p>
<p>Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php<br>
// Here we can see that all echo<br>
// statements are executed in the same manner<br><br>
$variable = 25;<br>
echo $variable;<br>
ECHO $variable; <br>
EcHo $variable; <br><br>
// but this line will show RUNTIME ERROR as <br>
// "Undefined Variable"<br>
echo $VARIABLE<br>
?><br>
</div><br>
<p>Output: </p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
25<br>
25<br>
25<br>
</div>
</div>
<div class="variables" id="variables">
<h1 class="y">PHP | Variables</h1>
<p>Variables in a program are used to store some values or data that can be used later in a program. PHP has its own way of declaring and storing variables.
</p><p>
There are few rules, that needs to be followed and facts that need to be kept in mind while dealing with variables in PHP:
</p>
<ul>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;" >Any variables declared in PHP must begin with a dollar sign ($), followed by the variable name.</li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;">A variable can have long descriptive names (like $factorial, $even_nos) or short names (like $n or $f or $x)</li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;">A variable name can only contain alphanumeric characters and underscores (i.e., ‘a-z’, ‘A-Z’, ‘0-9 and ‘_’) in their name.</li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;">Assignment of variables are done with assignment operator, “equal to (=)”. The variable names are on the left of equal and the expression or values are to the right of the assignment operator ‘=’.
</li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;">One must keep in mind that variable names in PHP names must start with a letter or underscore and no numbers.
</li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;">PHP is a loosely typed language and we do not require to declare the data types of variables, rather PHP assumes it automatically by analyzing the values. Same happens while conversion.
</li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;">PHP variables are case-sensitive, i.e., $sum and $SUM are treated differently.
</li>
</ul>
<p>Example: </p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php <br><br>
// These are all valid declarations<br>
$val = 5;<br>
$val2 = 2;<br>
$x_Y = "gfg"; <br>
$_X = "GeeksforGeeks";<br><br>
// This is an invalid declaration as it <br>
// begins with a number <br>
$10_ val = 56; <br><br>
// This is also invalid as it contains <br>
// special character other than _ <br>
$f.d = "num"; <br><br>
?><br>
</div>
<h2>Variable Scopes</h2>
<p>Scope of a variable is defined as its extent in program within which it can be accessed, i.e. the scope of a variable is the portion of the program with in which it is visible or can be accessed.</p>
<p>Depending on the scopes, PHP has three variable scopes:</p>
<h3>Local variables: </h3>
<p>The variables declared within a function are called local variables to that function and has its scope only in that particular function. In simple words it cannot be accessed outside that function. Any declaration of a variable outside the function with same name as that of the one within the function is a complete different variable. We will learn about functions in details in later articles. For now consider a function as a block of statements.</p>
<p>Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php <br><br>
$num = 60; <br>
<br>
function local_var() <br>
{ <br>
// This $num is local to this function <br>
// the variable $num outside this function <br>
// is a completely different variable <br><br>
$num = 50; <br>
echo "local num = $num \n"; <br>
} <br>
<br>
local_var(); <br>
<br>
// $num outside function local_var() is a <br>
// completely different Variable than that of <br>
// inside local_var() <br>
echo "Variable num outside local_var() is $num <br>\n"; <br>
<br>
?> <br>
</div>
<p>Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
local num = 50 <br>
Variable num outside local_var() is 60 <br>
</div>
<h3>Global variables:</h3>
<p>The variables declared outside a function are called global variables. These variables can be accessed directly outside a function. To get access within a function we need to use the “global” keyword before the variable to refer to the global variable.</p>
<p>Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php <br>
<br>
$num = 20; <br>
<br>
//function to demonstrate use of global variable<br>
//function global_var() <br>
{ <br>
<br>
// we have to use global keyword before <br>
// the variable $num to access within <br>
// the function<br>
global $num; <br>
<br>
echo "Variable num inside function : $num \n"; <br>
} <br>
<br>
global_var(); <br>
<br>
echo "Variable num outside function : $num \n"; <br>
<br>
?> <br>
</div>
<p>Output:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
Variable num inside function : 20 <br>
Variable num outside function : 20 <br>
</div>
<h3>Static variable:</h3>
<p> It is the characteristic of PHP to delete the variable, ones it completes its execution and the memory is freed. But sometimes we need to store the variables even after the completion of function execution. To do this we use static keyword and the variables are then called as static variables.</p>
<p>Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php <br>
<br>
// function to demonstrate static variables <br>
function static_var() <br>
{ <br>
// static variable <br>
static $num = 5; <br>
$sum = 2; <br>
<br>
$sum++; <br>
$num++; <br>
<br>
echo $num, "\n"; <br>
echo $sum, "\n"; <br>
} <br>
<br>
// first function call<br>
static_var(); <br>
<br>
// second function call<br>
static_var(); <br>
<br>
?> <br>
</div>
<p>Output:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
6<br>
3<br>
7<br>
3<br>
</div>
</div>
<div class="eprint" id="eprint">
<h1 class="y">PHP | echo and print</h1>
<p>We have seen echo statement quite frequently in PHP codes of previous article. It is the most basic way for displaying output in PHP.</p>
<p>However, there are two basic ways to get output in PHP:-<br> echo<br> print</p>
<h2>PHP echo statement</h2>
<p>In PHP ‘echo’ statement is a language construct and never behaves like a function, hence no parenthesis required. The end of echo statement is identified by the semi-colon (‘;’).
We can use ‘echo’ to output strings or variables. Below are some of the usage of echo statement in PHP:</p>
<h3>Displaying Strings:</h3>
<p>We can simply use the keyword echo followed by the string to be displayed withing quotes. Below example shows how to display strings with PHP:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
Hello,This is a display string example!<br>
</div>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php <br>
echo "Multiple ","argument ","string!"; <br>
?><br>
</div>
<h3>Displaying Strings:</h3>
<p>We can pass multiple string arguments to the echo statement instead of single string argument, separating them by comma (‘,’) operator. For example, if we have two strings say “Hello” and “World” then we can pass them as (“Hello”,”World”). Below example shows how to do this:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php <br>
echo "Multiple ","argument ","string!"; <br>
?><br>
</div>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
Multiple argument string!<br>
</div>
<h3>Displaying Variables:</h3>
<p>Displaying variables with echo statement is also as easy as displaying normal strings. Below example shows different ways to display variables with the help of PHP echo statement:-</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php <br>
//defining the variables <br>
$text = "Hello, World!"; <br>
<br>
$num1 = 10; <br>
<br>
$num2 = 20; <br>
<br>
//echoing the variables <br>
echo $text."\n"; <br>
<br>
echo $num1."+".$num2."="; <br>
<br>
echo $num1 + $num2;<br>
?><br>
</div>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
Hello, World!<br>
10+20=30!<br>
</div>
<p>The (.) operator in the above code can be used to concatenate two strings in PHP and the “\n” is used for a new line and is also known as line-break. We will learn about these in further articles.</p>
<h2>PHP print statement</h2>
<p>The PHP print statement is similar to the echo statement and can be used alternative to echo at many times.It is also language construct and so we may not use parenthesis : print or print(). The main difference between the print and echo statement is that print statement can have only one argument at a time and thus can print a single string. Also, print statement always returns a value 1.
Like echo, print statement can also be used to print strings and variables. Below are some examples of using print statement in PHP:</p>
<h3>Displaying String of Text:</h3>
<p> We can display strings with print statement in the same way we did with echo statements. The only difference is we can not display multiple strings separated by comma(,) with a single print statement. Below example shows how to display strings with the help of PHP print statement:-</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php<br>
print "Hello, world!"; <br>
?> <br>
</div>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
Hello, World!<br>
</div>
<h3>Displaying Variables: </h3>
<p>Displaying variables with print statement is also same as that of echo statement. The example below shows how to display variables with the help of PHP print statement:-</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php<br>
//defining the variables <br>
$text = "Hello, World!"; <br>
<br>
$num1 = 10;<br>
<br>
$num2 = 20;<br>
<br>
//echoing the variables <br>
print $text."\n"; <br>
<br>
print $num1."+".$num2."="; <br>
<br>
print $num1 + $num2; <br>
?> <br>
</div>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
Hello, World!<br>
10+20=30<br>
</div>
<h2>Comparison between Echo and Print in PHP:</h2>
<table style="width:50%;margin-left: 200px;">
<tr>
<th></th>
<th>echo</th>
<th>print</th>
</tr>
<tr>
<th>type</th>
<th>this is a type of output string</th>
<th>this is a type of output string</th>
</tr>
<tr>
<th>parenthesis</th>
<th>not written with parenthesis</th>
<th>it can or can not be written with parenthesis</th>
</tr>
<tr>
<th>strings</th>
<th>it can output one or morw strings</th>
<th>it can output only one string at a time, and returns 1.</th>
</tr>
<tr>
<th>functionality</th>
<th>echo is faster than print</th>
<th>print is slower than echo</th>
</tr>
<tr>
<th>argument</th>
<th>echo($arg1,$arg2.....)</th>
<th>print($arg)</th>
</tr>
</table><br>
</div>
<div class="dtypes" id="dtypes">
<h1 class="y">PHP | Data Types</h1>
<p>Data Types defines the type of data a variable can store. PHP allows eight different types of data types. All of them are discussed below. The first five are called simple data types and the last three are compound data types:</p>
<h2>Integer :</h2>
<p> Integers hold only whole numbers including positive and negative numbers, i.e., numbers without fractional part or decimal point. They can be decimal (base 10), octal (base 8) or hexadecimal (base 16). The default base is decimal (base 10). The octal integers can be declared with leading 0 and the hexadecimal can be declared with leading 0x. The range of integers must lie between -2^31 to 2^31.</p>
<p>Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">< ?php <br>
<br>
// decimal base integers <br>
$deci1 = 50; <br>
$deci2 = 654; <br>
<br>
// octal base integers <br>
$octal1 = 07; <br>
<br>
// hexadecimal base integers <br>
$octal = 0x45; <br>
<br>
$sum = $deci1 + $deci2; <br>
echo $sum; <br>
<br>
?> <br>
</div>
<p>Output:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">704</div>
<h2>Double:</h2>
<p> Can hold numbers containing fractional or decimal part including positive and negative numbers. By default, the variables add a minimum number of decimal places.<br>
Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
<? php <br>
<br>
$val1 = 50.85; <br>
$val2 = 654.26; <br>
<br>
$sum = $val1 + $val2; <br>
<br>
echo $sum; <br>
<br>
?> <br>
</div>
<p>Output:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">705.11</div>
<h2>String : </h2>
<p>Hold letters or any alphabets, even numbers are included. These are written within double quotes during declaration. The strings can also be written within single quotes but it will be treated differently while printing variables. To clarify this look at the example below.<br>
Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php
<br>
$name = "Krishna";<br>
echo "The name of the Geek is $name \n"; <br>
echo 'The name of the geek is $name'; <br>
<br>
?> <br>
</div>
<p>Output:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
The name of the Geek is Krishna <br>
The name of the geek is $name<br>
</div>
<h2>NULL:</h2>
<p> These are special types of variables that can hold only one value i.e., NULL. We follow the convention of writing it in capital form, but its case sensitive.<br>
Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php <br>
<br>
$nm = NULL; <br>
echo $nm; // This will give no output <br>
<br>
?> <br>
</div>
<h2>Boolean: </h2>
<p>Hold only two values, either TRUE or FALSE. Successful events will return true and unsuccessful events return false. NULL type values are also treated as false in Boolean. Apart from NULL, 0 is also consider as false in boolean. If a string is empty then it is also considered as false in boolean data type.<br>
Example:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php <br>
<br>
if(TRUE) <br>
echo "This condition is TRUE"; <br>
if(FALSE) <br>
echo "This condition is not TRUE"; <br>
?> <br>
</div>
<p>Output:</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
This condition is TRUE
</div>
<h2>Arrays:</h2>
<p> Array is a compound data-type which can store multiple values of same data type. Below is an example of array of integers.</p>
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">
< ?php <br>
<br>
$intArray = array( 10, 20 , 30); <br>
<br>
echo "First Element: $intArray[0]\n"; <br>
echo "Second Element: $intArray[1]\n"; <br>
echo "Third Element: $intArray[2]\n"; <br>
<br>
?> <br>
</div>
Output:
<div style="background-color: lightgrey;margin-left: 400px;width:400px;padding: 15px;">First Element: 10
Second Element: 20<br>
Third Element: 30<br>
</div>
<p>We will discuss all about arrays in details in further articles.</p>
</div>
<div class="deci" id="deci">
<h1 class="y">PHP | Decision Making</h1>
<p>
PHP allows us to perform actions based on some type of conditions that may be logical or comparative. Based on the result of these conditions i.e., either TRUE or FALSE, an action would be performed as asked by the user. It’s just like a two- way path. If you want something then go this way or else turn that way. To use this feature, PHP provides us with four conditional statements:
</p>
<ul>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;" > if statement
</li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;"> if…else statement
</li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;"> if…elseif…else statement
</li>
<li style="margin-left: 40px;color:#696969;font-size: 18px;padding: 5px;"> switch statement
</li>
</ul>