Chapter 10 Server Side Scripting Using PHP
Chapter 10 Server Side Scripting Using PHP
<?php
echo “My First PHP Program”;
?>
Ex: <?php
$a = “Hari”;
$b = 25;
?>
7
II. Data types
2. Arithmetic operators: + , - , *, /, %
4. Logical operators:
Logical AND operator: &&
Logical OR operator: ||
Logical NOT operator: !
echo print
echo can take more than Takes only one value
one values when used
without parenthesis.
Does not return any value Returns TRUE on
successful print, FALSE if
unable to print.
Little faster than print Little bit slower than
echo
$b = “Apple”;
var_dump($b);
//displays string(5) “Apple”
Ex: <?php
$mark = 30;
If ($mark > = 40)
{
echo “Passed”;
}
?>
Syntax:
<?php
if(condition)
{
//Statements to be executed if the
condition is true
}
?> Manu Ratheesh – GTHSS, Kattappana 20
c) switch statement
Ex: Print the day name corresponding to a day number
<?php
$d =2;
switch($d)
{
case 1: echo “Sunday”;
break;
case 2: echo “Monday”;
break;
……………………………………
……………………………………
……………………………………
default:
echo “invalid”;
}
?>
Syntax:
for(initialization; condition; update)
{
Statements
}
Syntax:
initialization;
while(condition)
{
Statements;
update statement;
}
Syntax:
initialization;
do
{
Statements
update;
} while(condition);
Manu Ratheesh – GTHSS, Kattappana 25
Arrays in PHP
• An array is a collection of same type of data.
Ex1:
$age = array(“Joe” => ”35”, “John” => ”30”, “Mini” => ”28”);
Ex2:
$cost = array(“Pen” => ”15”, “Pencil” => ”10”, “Brush” => ”20”);
Ex: <?php
function sample()
{
echo “Hello..welcome !!!”;
}
sample(); //function call
?>
Manu Ratheesh – GTHSS, Kattappana 30
2. String functions in PHP
Tier 2: Web server accepts the request from the browser, process
it and sends back the output to browser.
GET POST
The data visible in the The data is not visible in the
address bar. address bar.
Data is submitted as part of Data is submitted as part of
the URL http request.
Data sending is not secure. Data sending is secure.
2022
2022 Say
2021
2023 Say
2021 Say