SlideShare a Scribd company logo
PHP
      an introduction
What is PHP?


 • PHP stands for PHP: Hypertext Preprocessor

 • PHP is a server-side scripting language, which could
   be imbedded to HTML

 • PHP scripts are executed on the server

 • PHP supports many databases

 • PHP is an open source software, free to download
   and use

                                                          2
PHP Syntax

  <?php
  ….
  ?>


  <html>
       <body>
          <?php
          echo “Hello World”;
          ?>
       </body>
  </html>

                                3
Text Editors



• Dreamweaver Open as php and add code in code
  view. Use: Insert > php.
• Windows Notepad Make sure your files are saved
  with the .php extension.
• Microsoft Word is not optimal for editing PHP files.
  If you use it, you must save the file as plain text.




                                                         4
.html or .php: where

**Inline**                           **html code with echo and print*
<html>
                                    <?php
 <head>
 <title>HTML with PHP</title>        echo "<html>";
 </head>                             echo "<title>HTML with PHP</title>";
 <body>                              echo "<h1>My example</h1>";
   <h1>My Example</h1>
                                     //your php code here.
   <?php
     //your php code here            print "<i>Print works too!</i>";
   ?>
                                     echo “</html>”;
   <b>Here is some more html.</b>
   <?php                            ?>
     //your php code here
   ?>
 </body>
</html>                                                                 5
.html or .php??




     • Open new > Page type: php
     • Save as .php




                                   6
Variables


• Variables are used for storing a values, like text
   strings, numbers or arrays.
• When a variable is declared, it can be used over and
   over again in your script.
• All variables in PHP start with a $ sign symbol.
• The correct way of declaring a variable in PHP:

        $name = value;




                                                         7
Naming Rules for Variables


 • A variable name must start with a letter or an underscore
   “_”
 • A variable name can only contain alpha-numeric
   characters and underscores (a-z, A-Z, 0-9, and _ )
 • A variable name should not contain spaces. If a variable
   name is more than one word, it should be separated with
   an underscore ($my_string), or with capitalization
   ($myString)



                                                               8
The Concatenation Operator



The concatenation operator . is used to put two string together.



           <?php
             $txt1=“Hello World!”;
             $txt2=“What a nice day!”;
             echo $txt1 . “ ” . $txt2;
           ?>



                                                               9
Comments



 • Comments can be added to explain the
   PHP.

 • Single line comments start with //.

 • Multi line comments start with /* and end
   with */



                                               10
if…else Syntax

 <?php
      if (condition1)
       {code to be executed if condition1 is true};
      elseif (condition2)
       {code to be executed if condition2 is true};
      else
       {code to be executed if condition1 and condition2
             are not true};
 ?>

                                                           11
if…else Example

<?php
   $num1=10;
   $num2=20;
   if ($num1>$num2)
     echo “The first number is greater than the second.<br />”;
   elseif ($num1<$num2)
     {echo “The first number is smaller than the second.<br />”;
       echo “too bad”;
     }
   else
        echo “The first number is equal to the second.<br />”;
?>


                                                                   12
For Loop Syntax

  The for loop is used when you know in advance how
  many times the script should run.

  for (initial condition; end condition; increment)
    {
    code to be executed;
    }




                                                      13
For Loop Example


     <?php
        for ($i=0; $i<=5; $i++)
          {
           echo "The number is " . $i;
           echo “.<br />”;
           }
     ?>



                                         14
While Loop Syntax



     Initial variable;

     while (end variable)
        {
        code to be executed;

        variable increment;
        }


                               15
While Loop Example


    <php?
       $i=0;
       while ($i<=5)
       {
       echo "The number is " . $i . “.<br />”;
       $i++;
       }
    ?>


                                                 16
Function Syntax

   • need to be called in order to execute
   • Can be called multiple times with different variables

        function funname(var1, var2)
          {
          function code;
          }

        funname(var1, var2);



                                                             17
Function Example

   <?php

        function getGreeting($user){

            return “Hello, $user!”;

        }



        echo getGreeting(„Toby‟);

   ?>



                                       18
Function Example


 function caltax($num1)

    {$tax=0.0875;

     $total = $num1+($num1*$tax);

    echo "The total is $” . $total . ". <br />”;

    }

  caltax(100);



                                                   19
Works Cited




Most of the information on this PowerPoint are based
on W3Schools Online Web Tutorials PHP section.




                                                       20

More Related Content

PPTX
Intro to php
PDF
07 Introduction to PHP #burningkeyboards
ODP
PHP Tips for certification - OdW13
PPT
Php Lecture Notes
PDF
Introduction to PHP - Basics of PHP
PPTX
Php.ppt
Intro to php
07 Introduction to PHP #burningkeyboards
PHP Tips for certification - OdW13
Php Lecture Notes
Introduction to PHP - Basics of PHP
Php.ppt

What's hot (20)

PPT
Php(report)
PDF
Quick tour of PHP from inside
PPT
PHP POWERPOINT SLIDES
PPT
PHP - Introduction to PHP - Mazenet Solution
PPT
Introduction to PHP
PPTX
Basic of PHP
ODP
PHP Basic
PPTX
php basics
PPT
PPT
slidesharenew1
PPT
My cool new Slideshow!
PDF
Introduction to PHP
PDF
PHP7 is coming
PDF
Profiling php5 to php7
PDF
Data Types In PHP
PPT
Php i basic chapter 3
KEY
Intermediate PHP
PPTX
Loops PHP 04
PDF
PHP Loops and PHP Forms
Php(report)
Quick tour of PHP from inside
PHP POWERPOINT SLIDES
PHP - Introduction to PHP - Mazenet Solution
Introduction to PHP
Basic of PHP
PHP Basic
php basics
slidesharenew1
My cool new Slideshow!
Introduction to PHP
PHP7 is coming
Profiling php5 to php7
Data Types In PHP
Php i basic chapter 3
Intermediate PHP
Loops PHP 04
PHP Loops and PHP Forms
Ad

Viewers also liked (20)

PPTX
Week 2 HTML lists, hyperlinks, tables, and images
PPT
Week1 Dreamweaver and Server
PPTX
Web 2.0: its impact on library services
PPTX
Week1 Introduction
PPT
Week3 css
PPT
Hybrid in 5 minutes
PPT
Social and Mobile Media in the Librarian Profession
PPT
Week5 ap forms
PPT
Social media as a widget
PPTX
Week7 Dreamweaver Behavior & Image Hotspots
PPT
Week 2
PPT
JavaScript
PPTX
Trabajo de majo
PDF
Eenadu1
PDF
Meet your 2014 Growth Engine: Subscription Revenues
PPTX
PDF
Dreamforce 2013 One Hit Wonder Sessions
PDF
Serving the Next-Gen Customer
PDF
Renew OnDemand Brochure
PPT
Keebee/Keeping Kids Busy presentation april 2009
Week 2 HTML lists, hyperlinks, tables, and images
Week1 Dreamweaver and Server
Web 2.0: its impact on library services
Week1 Introduction
Week3 css
Hybrid in 5 minutes
Social and Mobile Media in the Librarian Profession
Week5 ap forms
Social media as a widget
Week7 Dreamweaver Behavior & Image Hotspots
Week 2
JavaScript
Trabajo de majo
Eenadu1
Meet your 2014 Growth Engine: Subscription Revenues
Dreamforce 2013 One Hit Wonder Sessions
Serving the Next-Gen Customer
Renew OnDemand Brochure
Keebee/Keeping Kids Busy presentation april 2009
Ad

Similar to PHP (20)

PPTX
Lecture 6: Introduction to PHP and Mysql .pptx
PPTX
FYBSC IT Web Programming Unit IV PHP and MySQL
PDF
Php a dynamic web scripting language
PPT
PHP - Web Development
PPT
Prersentation
PPTX
advancing in php programming part four.pptx
PPT
Php essentials
PPTX
Php operators
PDF
Wt unit 4 server side technology-2
PPT
What Is Php
 
DOCX
Free PHP Book Online | PHP Development in India
PPTX
PPTX
PHP BASICs Data Type ECHo and PRINT.pptx
PPT
Php basic for vit university
PPTX
php Chapter 1.pptx
PDF
PHP-Part2
PDF
Web Development Course: PHP lecture 1
PPTX
The basics of php for engeneering students
DOC
PHP MATERIAL
Lecture 6: Introduction to PHP and Mysql .pptx
FYBSC IT Web Programming Unit IV PHP and MySQL
Php a dynamic web scripting language
PHP - Web Development
Prersentation
advancing in php programming part four.pptx
Php essentials
Php operators
Wt unit 4 server side technology-2
What Is Php
 
Free PHP Book Online | PHP Development in India
PHP BASICs Data Type ECHo and PRINT.pptx
Php basic for vit university
php Chapter 1.pptx
PHP-Part2
Web Development Course: PHP lecture 1
The basics of php for engeneering students
PHP MATERIAL

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Insiders guide to clinical Medicine.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Institutional Correction lecture only . . .
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
Business Ethics Teaching Materials for college
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
01-Introduction-to-Information-Management.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Insiders guide to clinical Medicine.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Basic Mud Logging Guide for educational purpose
Microbial disease of the cardiovascular and lymphatic systems
Microbial diseases, their pathogenesis and prophylaxis
Institutional Correction lecture only . . .
Abdominal Access Techniques with Prof. Dr. R K Mishra
2.FourierTransform-ShortQuestionswithAnswers.pdf
Renaissance Architecture: A Journey from Faith to Humanism
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Pharma ospi slides which help in ospi learning
Business Ethics Teaching Materials for college
VCE English Exam - Section C Student Revision Booklet
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf

PHP

  • 1. PHP an introduction
  • 2. What is PHP? • PHP stands for PHP: Hypertext Preprocessor • PHP is a server-side scripting language, which could be imbedded to HTML • PHP scripts are executed on the server • PHP supports many databases • PHP is an open source software, free to download and use 2
  • 3. PHP Syntax <?php …. ?> <html> <body> <?php echo “Hello World”; ?> </body> </html> 3
  • 4. Text Editors • Dreamweaver Open as php and add code in code view. Use: Insert > php. • Windows Notepad Make sure your files are saved with the .php extension. • Microsoft Word is not optimal for editing PHP files. If you use it, you must save the file as plain text. 4
  • 5. .html or .php: where **Inline** **html code with echo and print* <html> <?php <head> <title>HTML with PHP</title> echo "<html>"; </head> echo "<title>HTML with PHP</title>"; <body> echo "<h1>My example</h1>"; <h1>My Example</h1> //your php code here. <?php //your php code here print "<i>Print works too!</i>"; ?> echo “</html>”; <b>Here is some more html.</b> <?php ?> //your php code here ?> </body> </html> 5
  • 6. .html or .php?? • Open new > Page type: php • Save as .php 6
  • 7. Variables • Variables are used for storing a values, like text strings, numbers or arrays. • When a variable is declared, it can be used over and over again in your script. • All variables in PHP start with a $ sign symbol. • The correct way of declaring a variable in PHP: $name = value; 7
  • 8. Naming Rules for Variables • A variable name must start with a letter or an underscore “_” • A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ ) • A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString) 8
  • 9. The Concatenation Operator The concatenation operator . is used to put two string together. <?php $txt1=“Hello World!”; $txt2=“What a nice day!”; echo $txt1 . “ ” . $txt2; ?> 9
  • 10. Comments • Comments can be added to explain the PHP. • Single line comments start with //. • Multi line comments start with /* and end with */ 10
  • 11. if…else Syntax <?php if (condition1) {code to be executed if condition1 is true}; elseif (condition2) {code to be executed if condition2 is true}; else {code to be executed if condition1 and condition2 are not true}; ?> 11
  • 12. if…else Example <?php $num1=10; $num2=20; if ($num1>$num2) echo “The first number is greater than the second.<br />”; elseif ($num1<$num2) {echo “The first number is smaller than the second.<br />”; echo “too bad”; } else echo “The first number is equal to the second.<br />”; ?> 12
  • 13. For Loop Syntax The for loop is used when you know in advance how many times the script should run. for (initial condition; end condition; increment) { code to be executed; } 13
  • 14. For Loop Example <?php for ($i=0; $i<=5; $i++) { echo "The number is " . $i; echo “.<br />”; } ?> 14
  • 15. While Loop Syntax Initial variable; while (end variable) { code to be executed; variable increment; } 15
  • 16. While Loop Example <php? $i=0; while ($i<=5) { echo "The number is " . $i . “.<br />”; $i++; } ?> 16
  • 17. Function Syntax • need to be called in order to execute • Can be called multiple times with different variables function funname(var1, var2) { function code; } funname(var1, var2); 17
  • 18. Function Example <?php function getGreeting($user){ return “Hello, $user!”; } echo getGreeting(„Toby‟); ?> 18
  • 19. Function Example function caltax($num1) {$tax=0.0875; $total = $num1+($num1*$tax); echo "The total is $” . $total . ". <br />”; } caltax(100); 19
  • 20. Works Cited Most of the information on this PowerPoint are based on W3Schools Online Web Tutorials PHP section. 20