PHP Presentation

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 18

PHP INTRODUCTION

•PHP is a recursive acronym for “PHP: Hypertext Preprocessor” -- It is a


widely-used open source general-purpose scripting language that is
especially suited for web development and can be embedded into HTML.
PHP INTRODUCTION

•> PHP is a server-side scripting language


•> PHP scripts are executed on the server
•> PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid,
PostgreSQL, Generic ODBC, etc.)
•> PHP is open source software
•> PHP is free to download and use
PHP INTRODUCTION

•> PHP runs on different platforms (Windows, Linux, Unix, etc.)


•> PHP is compatible with almost all servers used today (Apache,
IIS,XAMPP. etc)
•> PHP is FREE to download from the official PHP resource: www.php.net
•> PHP is easy to learn and runs efficiently on the server side
FIRST PHP-ENABLED PAGE

• Create a file named index.php


• Put it in your web servers directory
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo "<p>Hello World</p>"; ?>
</body>
</html>
VARIABLES

• Variables represented by a dollar sign followed


by the name of the variable
• name is case-sensitive.
• name starts with a letter or underscore, followed by
any number of letters, numbers, or underscores
• type is assigned by value
<?php
$var = "Bob";
$Var = "Joe";
echo "$var, $Var"; // outputs "Bob, Joe"
$x = 1;
$x = ‘abc’; // type can change if value changes
$4site = 'not yet'; // invalid; starts with a number $_4site = 'not yet'; // valid; starts with an
underscore
?>
ARRAYS

• created by the array() language-construct


• takes a certain number of comma-separated key
=> value pairs
<?php
$arr = array("foo" => "bar", 12 => true);
echo $arr["foo"]; // bar
echo $arr[12]; // 1
?> (see it here)
ARRAYS (CONT.)

<?php // Create a simple array.


$array = array(1, 2, 3, 4, 5);
print_r($array);
// Now delete every item, but leave the array
// itself intact:
foreach ($array as $i => $value) { unset($array[$i]);
}
print_r($array);
// Append an item (note that the new key is 5,
// instead of 0 as you might expect).
$array[] = 6;
print_r($array);
// Re-index:
$array = array_values($array);
$array[] = 7;
print_r($array);
?> (see result here)
PHP OPERATORS

•Operators are used to operate on values. There are four classifications of


operators:

• > Arithmetic
• > Assignment
• > Comparison
• > Logical
PHP OPERATORS
PHP OPERATORS
PHP OPERATORS
PHP OPERATORS
PHP CONDITIONAL STATEMENTS

•> Very often when you write code, you want to perform different actions for
different decisions.
•> You can use conditional statements in your code to do this.
•> In PHP we have the following conditional statements...
PHP CONDITIONAL STATEMENTS

•> if statement - use this statement to execute some code only if a specified
condition is true
•> if...else statement - use this statement to execute some code if a condition is
true and another code if the condition is false
PHP CONDITIONAL STATEMENTS

•> if...elseif....else statement - use this statement to select one


of several blocks of code to be executed
•> switch statement - use this statement to select one of many
blocks of code to be executed
THE IF
STATEMENT

The if statement executes some code if


one condition is true.
Syntax
if (condition) {
code to be executed if condition is true;
}
Example
 Output "Have a good day!" if the current time (HOUR) is less than 20:
<?php
$t = date("H");

if ($t < "20") {


echo "Have a good day!";
}
?>
IF...ELSE
STATEMENT
 The if...else statement executes some code if a condition is true and another code if that
condition is false.
 Syntax

if (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}

You might also like