Slide 1

Slide 1 text

php php MOHAMED LOEY

Slide 2

Slide 2 text

aGENda  Part I: Introduction  Part II: PHP Syntax  Part II: PHP Syntax  Part III: PHP Form Handling

Slide 3

Slide 3 text

aGENda  Part I: Introduction  What is PHP?  Why we use PHP?  Why we use PHP?  PHP Can  Set Up PHP on Your Own PC

Slide 4

Slide 4 text

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  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

Slide 5

Slide 5 text

whY wE USE php?  PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)  PHP is compatible with almost all servers used today (Apache, IIS, etc.)  PHP supports a wide range of databases  PHP supports a wide range of databases  PHP is easy to learn and runs efficiently on the server side  It is powerful enough to be at the core of the biggest blogging system on the web (WordPress)!  It is deep enough to run the largest social network (Facebook)!

Slide 6

Slide 6 text

php caN  Generate dynamic page content  Create, open, read, write, delete, and close files on the server Send and receive cookies  Send and receive cookies  Add, delete, modify data in your database  Encrypt data  Output images, PDF files, and even Flash movies

Slide 7

Slide 7 text

SET Up php ON YOUr OwN pc  Install a web server (Apache)  Install PHP  Install a database, such as MySQL  Install a database, such as MySQL  Example: XAMPP (Apache + MySQL + PHP + Perl)  XAMPP is the most popular PHP development environment

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

php SYNTax  PHP script can be placed anywhere in the document.  A PHP script starts with ends with ?>  The default file extension for PHP files is ".php".

Slide 10

Slide 10 text

SimpLE php cOdE

Slide 11

Slide 11 text

cOmmENTS iN php  A comment in PHP code is a line that is not read/executed as part of the program. PHP supports three ways of  PHP supports three ways of commenting:

Slide 12

Slide 12 text

php caSE SENSiTiViTY  In PHP, all user-defined functions, classes, and keywords (e.g. if, else, while, echo, etc.) are NOT case- sensitive. sensitive.  Example:

Slide 13

Slide 13 text

php caSE SENSiTiViTY  However; in PHP, all variables are case- sensitive.  $color, $COLOR, and $coLOR are treated as three different variables treated as three different variables  Example:

Slide 14

Slide 14 text

php VariabLES  Variables are "containers" for storing information.  A variable starts with the $ sign, followed by the name of the variable  A variable name must start with a letter or  A variable name must start with a letter or the 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 $Y are two different variables)

Slide 15

Slide 15 text

php VariabLES  PHP has no command for declaring a variable.  Example:

Slide 16

Slide 16 text

php EchO aNd priNT STaTEmENTS  In PHP there are two basic ways to get output: echo and print.  There are some differences between echo and print: print:  echo - can output one or more strings  print - can only output one string, and returns always 1  Example:

Slide 17

Slide 17 text

php OpEraTOrS  PHP Arithmetic Operators

Slide 18

Slide 18 text

php OpEraTOrS  PHP Arithmetic Operators Example:

Slide 19

Slide 19 text

php OpEraTOrS  PHP Assignment Operators

Slide 20

Slide 20 text

php OpEraTOrS  PHP Assignment Operators Example:

Slide 21

Slide 21 text

php OpEraTOrS  PHP String Operators

Slide 22

Slide 22 text

php OpEraTOrS  PHP String Operators Example:

Slide 23

Slide 23 text

php OpEraTOrS  PHP Increment / Decrement Operators

Slide 24

Slide 24 text

php OpEraTOrS  PHP Increment / Decrement Operators Example:

Slide 25

Slide 25 text

php OpEraTOrS  PHP Comparison Operators

Slide 26

Slide 26 text

php OpEraTOrS  PHP Comparison Operators Example:

Slide 27

Slide 27 text

php OpEraTOrS  PHP Logical Operators

Slide 28

Slide 28 text

php OpEraTOrS  PHP Array Operators

Slide 29

Slide 29 text

php OpEraTOrS  PHP Array Operators Example:

Slide 30

Slide 30 text

php cONdiTiONaL STaTEmENTS  In PHP we have the following conditional statements:  if statement - executes some code only if a specified condition is true condition is true  if...else statement - executes some code if a condition is true and another code if the condition is false  if...elseif....else statement - selects one of several blocks of code to be executed  switch statement - selects one of many blocks of code to be executed

Slide 31

Slide 31 text

php cONdiTiONaL STaTEmENTS  If else Example:

Slide 32

Slide 32 text

php cONdiTiONaL STaTEmENTS  Switch example:

Slide 33

Slide 33 text

php LOOpS  In PHP, we have the following looping statements:  while - loops through a block of code as long as the specified condition is true specified condition is true  do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true  for - loops through a block of code a specified number of times  foreach - loops through a block of code for each element in an array

Slide 34

Slide 34 text

php LOOpS  PHP while Loop example:

Slide 35

Slide 35 text

php LOOpS  PHP do...while Loop example:

Slide 36

Slide 36 text

php LOOpS  PHP for Loop example:

Slide 37

Slide 37 text

php LOOpS  PHP foreach Loop example:

Slide 38

Slide 38 text

php FUNcTiONS  A function is a block of statements that can be used repeatedly in a program.  A function will not execute immediately when a page loads. page loads.  A function will be executed by a call to the function.

Slide 39

Slide 39 text

php FUNcTiONS  PHP function examples:

Slide 40

Slide 40 text

php arraYS  An array is a special variable, which can hold more than one value at a time.  Example:

Slide 41

Slide 41 text

php aSSOciaTiVE arraYS  Associative arrays are arrays that use named keys that you assign to them.  Example:

Slide 42

Slide 42 text

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,  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

Slide 43

Slide 43 text

aGENda  Part III: PHP Form Handling  PHP GET vs. POST  PHP $_GET  PHP $_GET  PHP $_POST

Slide 44

Slide 44 text

php FOrm haNdLiNG  One of the most powerful features of PHP is the way it handles HTML forms. The basic concept that is important to understand is that any form element will automatically be available to your PHP scripts. that any form element will automatically be available to your PHP scripts.  The PHP $_GET and $_POST are used to collect form-data.

Slide 45

Slide 45 text

php GET VS. pOST  Both GET and POST create an array (e.g. array( key => value, key2 => value2, key3 => value3, ...)). This array holds key/value pairs, where keys are the names of the form controls and values are the input data from the user. data from the user.  When to use GET?  Information sent from a form with the GET method is visible to everyone  facebook.com?welcome.php?name=Mohamed  When to use POST?  Information sent from a form with the POST method is invisible to others  facebook.com?welcome.php

Slide 46

Slide 46 text

php $_GET  Example:

Slide 47

Slide 47 text

php $_GET  When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named "welcome.php". "welcome.php".  welcome.php

Slide 48

Slide 48 text

php $_GET  Result:  Welocome.php Output

Slide 49

Slide 49 text

php $_pOST  Example:

Slide 50

Slide 50 text

php $_pOST  When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named "welcome.php". "welcome.php".  welcome.php

Slide 51

Slide 51 text

php $_pOST  Result:  Welocome.php Output

Slide 52

Slide 52 text

ThaNK U ThaNK U