Exp1 Notes
Exp1 Notes
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
Variables in PHP
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;
}
do {
code to be executed;
} while (condition is true);
for loop : loops through a block of code a specified number of times
foreach loop : loops through a block of code for each element in an array
$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();
?>