PHP Comprehensive Overview
-
Upload
httpwwwbuedueg -
Category
Technology
-
view
888 -
download
0
Transcript of PHP Comprehensive Overview
PHPMOHAMED LOEY
Agenda
Part I: Introduction
Part II: PHP Syntax
Part III: PHP Form Handling
Agenda
Part I: Introduction
What is PHP?
Why we use PHP?
PHP Can
Set Up PHP on Your Own PC
What is PHP?
PHP is a server scripting language, and
is a powerful tool for making dynamic
and interactive Web pages quickly.
PHP is a widely-used, open source
scripting language
PHP scripts are executed on the server
PHP costs nothing, it is free to
download and use
Why we use PHP?
PHP runs on various platforms (Windows, Linux,Unix, Mac OS X, etc.)
PHP is compatible with almost all servers usedtoday (Apache, IIS, etc.)
PHP supports a wide range of databases
PHP is easy to learn and runs efficiently on theserver side
It is powerful enough to be at the core of thebiggest blogging system on the web(WordPress)!
It is deep enough to run the largest socialnetwork (Facebook)!
PHP Can
Generate dynamic page content
Create, open, read, write, delete, andclose files on the server
Send and receive cookies
Add, delete, modify data in yourdatabase
Encrypt data
Output images, PDF files, and evenFlash movies
Set Up PHP on Your Own PC
Install a web server (Apache)
Install PHP
Install a database, such as MySQL
Example: XAMPP (Apache + MySQL +
PHP + Perl)
XAMPP is the most popular PHP
development environment
Agenda
Part II: PHP Syntax
PHP Syntax
Comments in PHP
PHP Case Sensitivity
PHP Variables
PHP echo and print Statements
PHP Operators
PHP Conditional Statements
PHP Loops
PHP Functions
PHP Arrays
PHP Syntax
PHP script can be placed anywhere inthe document.
A PHP script starts with <?php andends with ?>
The default file extension for PHP filesis ".php".
Simple PHP Code
Comments in PHP
A comment in PHP code is a line that isnot read/executed as part of theprogram.
PHP supports three ways ofcommenting:
PHP Case Sensitivity
In PHP, all user-defined functions,classes, and keywords (e.g. if, else,while, echo, etc.) are NOT case-sensitive.
Example:
PHP Case Sensitivity
However; in PHP, all variables are case-sensitive.
$color, $COLOR, and $coLOR aretreated as three different variables
Example:
PHP Variables
Variables are "containers" for storinginformation.
A variable starts with the $ sign, followed bythe name of the variable
A variable name must start with a letter orthe underscore character
A variable name cannot start with a number
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9,and _ )
Variable names are case sensitive ($y and $Yare two different variables)
PHP Variables
PHP has no command for declaring a variable.
Example:
PHP echo and print Statements
In PHP there are two basic ways to get output:echo and print.
There are some differences between echo andprint:
echo - can output one or more strings
print - can only output one string, and returns always1
Example:
PHP Operators
PHP Arithmetic Operators
PHP Operators
PHP Arithmetic Operators Example:
PHP Operators
PHP Assignment Operators
PHP Operators
PHP Assignment Operators Example:
PHP Operators
PHP String Operators
PHP Operators
PHP String Operators Example:
PHP Operators
PHP Increment / Decrement Operators
PHP Operators
PHP Increment / Decrement OperatorsExample:
PHP Operators
PHP Comparison Operators
PHP Operators
PHP Comparison Operators Example:
PHP Operators
PHP Logical Operators
PHP Operators
PHP Array Operators
PHP Operators
PHP Array Operators Example:
PHP Conditional Statements
In PHP we have the following conditionalstatements:
if statement - executes some code only if a specifiedcondition is true
if...else statement - executes some code if acondition is true and another code if the condition isfalse
if...elseif....else statement - selects one of severalblocks of code to be executed
switch statement - selects one of many blocks ofcode to be executed
PHP Conditional Statements
If else Example:
PHP Conditional Statements
Switch example:
PHP Loops
In PHP, we have the following loopingstatements:
while - loops through a block of code as long as thespecified condition is true
do...while - loops through a block of code once, andthen repeats the loop as long as the specifiedcondition is true
for - loops through a block of code a specifiednumber of times
foreach - loops through a block of code for eachelement in an array
PHP Loops
PHP while Loop example:
PHP Loops
PHP do...while Loop example:
PHP Loops
PHP for Loop example:
PHP Loops
PHP foreach Loop example:
PHP Functions
A function is a block of statements that can beused repeatedly in a program.
A function will not execute immediately when apage loads.
A function will be executed by a call to thefunction.
PHP Functions
PHP function examples:
PHP Arrays
An array is a special variable, which can holdmore than one value at a time.
Example:
PHP Associative Arrays
Associative arrays are arrays that use namedkeys that you assign to them.
Example:
PHP Sorting Arrays
PHP array sort functions:
sort() - sort arrays in ascending order
rsort() - sort arrays in descending order
asort() - sort associative arrays in ascending order,according to the value
ksort() - sort associative arrays in ascending order,according to the key
arsort() - sort associative arrays in descending order,according to the value
krsort() - sort associative arrays in descending order,according to the key
Agenda
Part III: PHP Form Handling
PHP GET vs. POST
PHP $_GET
PHP $_POST
PHP Form Handling
One of the most powerful features of PHP isthe way it handles HTML forms. The basicconcept that is important to understand isthat any form element will automatically beavailable to your PHP scripts.
The PHP $_GET and $_POST are used tocollect form-data.
PHP GET vs. POST
Both GET and POST create an array (e.g. array( key=> value, key2 => value2, key3 => value3, ...)). Thisarray holds key/value pairs, where keys are thenames of the form controls and values are the inputdata from the user.
When to use GET?
Information sent from a form with the GET methodis visible to everyone
facebook.com?welcome.php?name=Mohamed
When to use POST?
Information sent from a form with the POSTmethod is invisible to others
facebook.com?welcome.php
PHP $_GET
Example:
PHP $_GET
When the user fills out the form above andclicks the submit button, the form data is sentfor processing to a PHP file named"welcome.php".
welcome.php
PHP $_GET
Result:
Welocome.php Output
PHP $_POST
Example:
PHP $_POST
When the user fills out the form above andclicks the submit button, the form data is sentfor processing to a PHP file named"welcome.php".
welcome.php
PHP $_POST
Result:
Welocome.php Output
THANK U