
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































PHP Scripting Language
Essentials of PHP - Operators and Flow Control - Strings and Arrays
output any text, such as XHTML and XML.
Softwareās required to execute PHP application:
E.g.: Microsoft IIS, Apache, Xitami, sambar server etc.,
The current version used is PHP6.
Any web browser available in the system can be used.
āHereā documents
E.g: Program 1.
Displaying text from PHP
Displaying text from PHP Here's what PHP has to say: php
/* This is an example Program for multi-line comment in php */ echo āhello indiaā; ?>
In PHP variable name begins with a $ sign.
Rules for naming a variable:
In php the variables need not be declared.
Whenever a variable is required, they should be assigned some value.
Depending on the value stored in the variable, the php automatically assigns data type.
The values in a variable are not static.
To assign data to variable, $[var nm] = value;
The = sign is the assignment operator in php. It allows you to assign data to variable.
E.g.: Program 1.
Data should be assigned some value before attempting to read a variables value.
To destroy a variable, unset() function is used.
Unset() destroys the variable and the associated data in memory.
Interpolating string:
E.g. echo āvalue in x isā , $x ;
String Interpolation is a feature in PHP where the name of variables can be given inside the double quotes itself.
In such a case as enclosing the variable in the string, echo string should be given in-between double quotes only. E.g. Program 1.
In the above program, $x is included in-between double quotes. PHP will place the value held by $x into the string like as follow:
The above echo will produce error Notice It should be altered like,: Undefined variable: typeball in C:\xampp\htdocs\prg1-9.PHP on line 3. echo ā$type ballā; Where the output will be,
echo ā{$type}ballā; This will return ābasketballā.
E.g. echo ā$type ballā; This will return $type ball.
E.g. Echo ā$type ballā; This would return ā$type ballā.
Creating Variable Variables:
E.g. Program1. php
Eg: Program 1. ",$i; ?>
is_int (), is_float (), is_array (), and so on.
$res = $op1+$op2; echo $res; $res = $op1- $op2; echo "",$res; ?>
The \ symbol is a sensitive character so it should be escaped by (\) a double slash.
Operator Operation Example Result == Equal $a == $b TRUE if $a is equal to $b === Identical $a === $b TRUE if $a is equal to $b, and they are of the same type. != Not equal $a != $b TRUE if $a is not equal to $b <> Not equal $a <> $b TRUE if $a is not equal to $b !== Not Identical $a !== $b TRUE if $a is not equal to $b, or they are not of the same type. < Less than $a < $b True if $a is strictly less than $b > Greater than $a > $b True if $a is strictly greater than $b <= Less than or equal to $a <= $b True if $a is less than or equal to $b >= Greater than or equal to $a >= $b True if $a is greater than or equal to $b
E.g: Program 1. warning "; echo " your time is up"; } ?>
Operator Operation Example Result and And $a and $b TRUE if both $a and $b are TRUE or Or $a or $b TRUE if both $a or $b is TRUE xor Xor $a xor $b TRUE if either $a or $b are TRUE, but not both ! Not !$a TRUE if $a is not TRUE && And $a && $b TRUE if both $a and $b are TRUE || Or $a || $b TRUE if either $a and $b is TRUE
ā&&ā and āandā both work the same way, as is ā||ā and āorā.
Eg: Program 1. floor(no1) = ".floor($no1); echo "ceil(no1) = ".ceil($no1); echo "decbin(floor(no1)) = ".decbin(floor($no1)); ?>
If statement:
Compound if statement: $tem = 66; if($tem > 65) { echo "it "; echo "is "; echo "nice."; }
Compound statements are included in between curly braces { }.
E.g: Program 1.
This example checks for the value in the variable is floating point, then adds 4.5 to it and uses the var_dump() php function to display the value in the browser.
The else Statement:
else { echo "Too Hot"; } ?>
Switch Statement
Syntax: switch (test value) { case expr 1: stamt1; [break;] case expr 2: stmt2; [break;] case expr 3; stmt3; [break;] . . . [default: Default stmt:] }
E.g: Program 1.
For loop