0% found this document useful (0 votes)
1 views

Exp1 Notes

The document outlines the development of simple web applications using control structures in PHP, focusing on understanding conditional structures and loop constructs. It explains PHP as a server-side scripting language, detailing syntax for comments, variables, conditional statements, loops, and functions. Examples are provided to illustrate the use of PHP code within web applications.

Uploaded by

chinjusneha05
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Exp1 Notes

The document outlines the development of simple web applications using control structures in PHP, focusing on understanding conditional structures and loop constructs. It explains PHP as a server-side scripting language, detailing syntax for comments, variables, conditional statements, loops, and functions. Examples are provided to illustrate the use of PHP code within web applications.

Uploaded by

chinjusneha05
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Exp.

No :1 PHP WEB APPLICATIONS USING CONTROL STRUCTURES

AIM :- Develop simple web applications using control structures in PHP


OBJECTIVES:
1 To understand conditional structures in PHP

2 To understand various loop constructs in PHP

THEORY:
PHP (Hypertext Preprocessor) is a server-side scripting language designed for
web development but also used as a general-purpose programming language. PHP is a
free software released under the terms of PHP License. PHP code is interpreted by a
web server via a PHP processor module, which generates the resulting web page. PHP
commands can optionally be embedded directly into an HTML source document
rather than calling an external file to process data. It has also evolved to include a
command-line interface capability and can be used in standalone graphical
applications.

PHP scripting block always starts with <?php and ends with ?>. A PHP scripting
block can be placed anywhere in the document. A PHP file normally contains HTML tags,
just like an HTML file, and some PHP scripting code. The file must have a .php extension
to execute.

Comments in PHP

Use // to make a single-line comment. /* and */ to make a large comment block

Variables in PHP

- All variables in PHP start with a $ sign symbol.


- A variable name must start with a letter or the underscore character
- Variable names are case-sensitive ($age and $AGE are two different variables)

Example:
<?php
$x = 5;
$y = 4;
$z=$x+$y;
echo “$x + $y = $z”;
?>
PHP Conditional Statements
The if Statement
Syntax
if (condition) {
code to be executed if condition is true;
}

The if...else Statement


Syntax
if (condition) {
code to be executed if condition is true;
}
else {
code to be executed if condition is false;
}
The if...elseif...else Statement
Syntax
if (condition) {
code to be executed if this condition is true;
}
elseif (condition) {
code to be executed if first condition is false and this condition is true;
}
else {
code to be executed if all conditions are false;
}
PHP Loops

In PHP, there are four looping statements:


while loop : loops through a block of code as long as the specified condition is true

while (condition is true) {


code to be executed;
}
do...while loop : loops through a block of code once, and then repeats the loop as long as the
specified condition is true

do {
code to be executed;
} while (condition is true);
for loop : loops through a block of code a specified number of times

 for (init counter; test counter; increment counter) {


code to be executed;
}

foreach loop : loops through a block of code for each element in an array

foreach ($array as $value) {


code to be executed;
}
Example
<?php 

$size=array("Big","Medium","Short");
foreach( $size as $s )
{
echo "Size is: $s<br />";
}
?> 

PHP Functions

Syntax
function functionName()
{
code to be executed;
}
Example
<?php
function writeName()
{
echo “Joan";
}
echo "My name is : ";
writeName();
?>

You might also like