Web Technologiesunit 4
Web Technologiesunit 4
Web Technologiesunit 4
,
Printf("The name: %s" $name):
75 Soe,
Sods,
“Mitra
OS eee
TECHNICAL PUBLICATION:6-14
Web Technologies
Output
SD output Derno - Morilla Firefox
File’ Edit View History Bookmarks Tools Help
|Elouput demo Lei
¢
“Back Forward
Welcome to my Website
The roll number: 1
‘The name: AAA
|
|
|
i
|
|
1
|
|
Display using echo
© The echo is a simple statement that can be used with or without parenthesis.
* For example -
echo “I am proud of my country"
* The echo statement can display the text and variable value as follows -
$a=10;
echo “a
+ $a;
Difference between echo and print
(seve. \ echo in PHP print in PHP
fi \ The echo can output one or more strings. | Print ean only output one string.
2
2. _| cet is taster than print
print is slower than echo
| 3 \ Udoes not retum any value
Review Questions
List and explain various data types in PHP.
Explain
Print always retums 1
iferent types of operators used in PHP.
Explain the term expression with suitable example.
FEM Program Controt Statements
Decision inaking control statements decide the order of execution of the statement
on cenain conditions. Various types of decision making control statements are ~
TECHNICAL PUBLICATIONS an ups fr Inowedgoe
web Technologies 6-15
4. The if Statement
syntax
igesoression)
{
statement inside;
}
statement outside;
Example
Sb)
echo 'a is greater than b’;
PP
2. The if-else Statement
Syntax
ilexpression)
st
Statements;
}
se
if
‘ Statements;
Example
oo 8-18
PHP end XML
The {low chart for break statement is,
gynt®
ek
oa
4
|
7 4
For example
ee i
4
break; |
; |
echo Si
echo "
% i
. ied
Output vi
F Pa
U : eel
The conti
Continue Statement
* The conti; 2
us ‘ontinue statement is used to skip some statements inside the leop. The continus
iia eR cei ay eee we "
“i ‘ment is used with decision making statement such as ifclse.
— Sar
ntinue statement forces to execute the next iteration of the loop to execute,
* The flow
: lowchart for continue statement is,
YMtax. ‘
Caine
TECHNICAL PUBLICATIONS® - an epee fr ArmlessWeb Technologies _
Enter loop,
PHP and cy
False
Condition =
Exit loop
Remaining
statements
For example
si=0; ;
for (Si = O$i <= 7Si++)
;
(81
echo Si;
echo "
"
/ Output
WAwWaANAS
TECHNICAL PUBLICATIONS? an upnue for knowledgea
spo tetoios 6-21
i
n break and continue
nce betwee!
piffere'
(ue break
PHP and XML
continue
This statement terminates the execution of
remaining iteration of the loop.
M terminates only the current iteration of
the loop.
2. It causes early termination of the entire
loop.
It causes early execution of the next
iteration.
[ERB Looping
Loop control structures are used to execute the
certain number of times,
4.The while Loop
Syntax
while(condition){
1 Code to be executed
}
Example
,
Sis,
} a
»
Certain group of statements repetitively for
TEGHNIGAL PUBLICATIONS® ~
‘an upnnst forknowtesge
|
jWeb Technologies B28,
[ Srrcota Fetes
Be Est ew tien Resins lect Hep
Bhrepnccamentp rics Leeptemsl pop
2. The do...while Loop
In this type of looping statement the block of code executed once and then condition is
evaluated. If the condition is true the statement is repeated as long as the specified condition is
true.
Syntax
dof
I] Code wo be executed
} while(condizion);
Example
";
print $i,
print "
";
Sit
} webile($i<=10};
>
Output
The output will be same as above.
TECHIUCAL PUBLICATIONS? an up tsa for tnomtodpe,
yop Toonmologies 8 PHP and XML
4, The for LOOP
the for loop repeats a block of code as long as a certain condition is met. It is typically
{io execute a block of code for certain numberof times.
vse
syntax .
ogniatzaion; condition; increment)(
1) Gode to be executed
,
Example
<
num | Sqr | Cube | Quad | " for(Scount=1,$count<=10Scount+ +) et ‘ $sq=$count*$count; Scube=Scount*$count*$count; Squad=$count* $count*Scount*$count;| ap roo0i8 6-31 PHP and XML we int "<>Scount | Ssq | Scubed/td> | Squad | "; gree ° ody? pul? Output squaRe,. x € ® localhestipnp-exarpl | Table [Cube (Quad te 16. ist [256 [e2s ie [i296 B43 Pao 12 [4096 [729 [6561 | 1000 {10000 WWth the use of PHP, suite case and ifstructre perform te fllowing and print appropriate message. 9 Get today's date ti) If date is 3, tis dentist appointment 'W) If date is 10, go to conference. Sol nn Idate is other than 3 and 10, no events are scheduled. “boon, Stings PE D> “bodys, re tat eeY date is" . date(“d/m/y"). “
---|---|---|
S1.No. | std>Price | TECHHICAL PUBLICATIONS? un opts for nowlodgoenti sup 2: Create a PHP script which will read out the data entered by the user using HTML ‘ fann. The code is as follows - FHP Document{formdemo.php]