Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP

 PHP

Mohamed Loey

May 27, 2015
Tweet

More Decks by Mohamed Loey

Other Decks in Education

Transcript

  1. aGENda  Part I: Introduction  Part II: PHP Syntax

     Part II: PHP Syntax  Part III: PHP Form Handling
  2. aGENda  Part I: Introduction  What is PHP? 

    Why we use PHP?  Why we use PHP?  PHP Can  Set Up PHP on Your Own PC
  3. 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
  4. 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)!
  5. 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
  6. 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
  7. 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
  8. php SYNTax  PHP script can be placed anywhere in

    the document.  A PHP script starts with <?php and ends with ?> ends with ?>  The default file extension for PHP files is ".php".
  9. 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:
  10. 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:
  11. 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:
  12. 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)
  13. 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:
  14. 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
  15. 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
  16. 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.
  17. php arraYS  An array is a special variable, which

    can hold more than one value at a time.  Example:
  18. php aSSOciaTiVE arraYS  Associative arrays are arrays that use

    named keys that you assign to them.  Example:
  19. 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
  20. aGENda  Part III: PHP Form Handling  PHP GET

    vs. POST  PHP $_GET  PHP $_GET  PHP $_POST
  21. 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.
  22. 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
  23. 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
  24. 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