SlideShare ist ein Scribd-Unternehmen logo
1 von 16
PHP Introduction


   Mohamed Ashraf
PHP Hypertext Preprocessor

   No joke, that’s what it stands for
   Now very widely used for websites
   Only three years ago it was considered a
    risky alternative for development
   Has a lot of community support
Simple PHP

   PHP is meant to be invoked inline with
    content
   Page “escapes” into and out of a regular html
    document
   File extension is .php (was .php3 for version
    3)
   Initial use was control flow and simple
    scripting
A quick example

   <html>
    <head>Test page</head>
    <body>
    The time is now
    <?php
        echo date();
     ?>
     <hr>
    </body>
    </html>
A quick example

   <html>
    <head>Test page</head>
    <body>
    The time is now
    <?php              here we “jump into” php
        echo date();
     ?>                here we “jump” back out
     <hr>
    </body>
    </html>
Another example
 <?php
      include “utilities.php”;
 ?>
 <html>
 <head>Test page</head>
 <body>
 <?php
      if ($utils->isFriendly()) {
                  echo “The time is now “ . date();
      } else {
                  echo “I will not give you the time of day”;
      }
 ?>
 <hr>
 </body>
 </html>
Another example – harder to read
    <?php
            include “utilities.php”;
    ?>
    <html>
    <head>Test page</head>
    <body>
    <?php
            if ($utils->isFriendly()) {
                         echo “The time is now “ . date();
            } else {
    ?>
<i>I will not give you the time of day!</i>
    <?php
            }
   ?>
   <hr>
    </body>
    </html>
More PHP language details

   Variables are implicitly typed
       This is good
       This is bad
   Variables start with $
   All get/post variables automatically defined
       With most default server settings
       With an inline directive if need be
Defined variable example
   foo.html:
    <html><head></head><body>
    <form submit=“getFoo.php”>
    Enter your name:
    <input type=“text” name=“username”>
    <input type=“submit”>
    </body></html>
   getFoo.php:
    <html><head></head></body>
    Your name is
    <?php
           if (!strcmp($username)) {
                       echo $username;
           } else {
                       echo “not given”;
           }
    ?>
    !<br>
    </body></html>
Function list examples

   http://www.php.net/manual/en/function.strlen.
    php
       All string functions
       Some are “obvious” to c programmers
           strlen, printf, fprintf, strpos
       Some are web tailored
           htmlentities, htmlspecialchars
       Others are new (hacky)
           addcslashes, explode, soundex, quotemeta, …
Classes

   OOP
       Class structures will be defined, helping
        integration with other apps and work together
       APIs followed by implementation
   Inheritance
   Object serialization
       “Magic functions”
Class example
class Cart
{
   var $items; // Items in our shopping cart
   // Add $num articles of $artnr to the cart
   function add_item ($artnr, $num)
   {
      $this->items[$artnr] += $num;
   }
   // Take $num articles of $artnr out of the cart
   function remove_item ($artnr, $num)
   {
      if ($this->items[$artnr] > $num) {
          $this->items[$artnr] -= $num;
          return true;
      } else {
          return false;
      }
   }
}
Inheritance example
 Class ParentObject {
   var $value;
  function ParentObject() {
     $this->value = 42;
  }
 }
 class MemberObject extends ParentObject {
   var $string;
    function MemberObject() {
      $this->string = "This is a test string.";
 $this->ParentObject();
   }
 }
 class ObjTest {
    var $ObjPointer;
   function ObjTest() {
      $tmp = new MemberObject;
 $this->ObjPointer = $tmp;
   }
 }
 $object = new ObjTest;
 echo "String Contents: " . $object->ObjPointer->string . "n";
 echo "Value Contents: " . $object->ObjPointer->value . "n";
Back to being hacky…

   “->” is NOT the same thing as it is in c++
       No pointers in PHP
       ONLY a member operator
   Oh, you wanted pointers?
       Variable variables
           Yeah, you heard right
               Don’t get me started…
Variable variables and classes example

 class a {
    var $b;
 }

 $object = new a;
 $object->b = "hello";
 $member_name = 'b';
 echo $object->$member_name;
 $object->$member_name = " world";
 echo $object->$member_name;
Resources

   http://www.php.net
   http://www.w3schools.com

Weitere ähnliche Inhalte

Was ist angesagt?

Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11
Goro Fuji
 

Was ist angesagt? (20)

PHP - Introduction to PHP
PHP -  Introduction to PHPPHP -  Introduction to PHP
PHP - Introduction to PHP
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
Phphacku iitd
Phphacku iitdPhphacku iitd
Phphacku iitd
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Php functions
Php functionsPhp functions
Php functions
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
PHP - Introduction to PHP Functions
PHP -  Introduction to PHP FunctionsPHP -  Introduction to PHP Functions
PHP - Introduction to PHP Functions
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in function
 
Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 

Ähnlich wie Php

course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 
Cakefest 2010: API Development
Cakefest 2010: API DevelopmentCakefest 2010: API Development
Cakefest 2010: API Development
Andrew Curioso
 

Ähnlich wie Php (20)

Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
PHP
PHP PHP
PHP
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
 
Php
PhpPhp
Php
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
PHP-Part1
PHP-Part1PHP-Part1
PHP-Part1
 
Intro to php
Intro to phpIntro to php
Intro to php
 
Cakefest 2010: API Development
Cakefest 2010: API DevelopmentCakefest 2010: API Development
Cakefest 2010: API Development
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricks
 
Framework
FrameworkFramework
Framework
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
Hacking with hhvm
Hacking with hhvmHacking with hhvm
Hacking with hhvm
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

Mehr von mohamed ashraf (13)

Seo wordpress
Seo wordpressSeo wordpress
Seo wordpress
 
File9350
File9350File9350
File9350
 
Css
CssCss
Css
 
Css
CssCss
Css
 
Basic css-tutorial
Basic css-tutorialBasic css-tutorial
Basic css-tutorial
 
Html tutorial
Html tutorialHtml tutorial
Html tutorial
 
Html css
Html cssHtml css
Html css
 
15 03-0460-00-0000-css-tutorial
15 03-0460-00-0000-css-tutorial15 03-0460-00-0000-css-tutorial
15 03-0460-00-0000-css-tutorial
 
Php
PhpPhp
Php
 
Ubi comp27nov04
Ubi comp27nov04Ubi comp27nov04
Ubi comp27nov04
 
Phpwebdevelping
PhpwebdevelpingPhpwebdevelping
Phpwebdevelping
 
Php
PhpPhp
Php
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Php

  • 1. PHP Introduction Mohamed Ashraf
  • 2. PHP Hypertext Preprocessor  No joke, that’s what it stands for  Now very widely used for websites  Only three years ago it was considered a risky alternative for development  Has a lot of community support
  • 3. Simple PHP  PHP is meant to be invoked inline with content  Page “escapes” into and out of a regular html document  File extension is .php (was .php3 for version 3)  Initial use was control flow and simple scripting
  • 4. A quick example  <html> <head>Test page</head> <body> The time is now <?php echo date(); ?> <hr> </body> </html>
  • 5. A quick example  <html> <head>Test page</head> <body> The time is now <?php here we “jump into” php echo date(); ?> here we “jump” back out <hr> </body> </html>
  • 6. Another example <?php include “utilities.php”; ?> <html> <head>Test page</head> <body> <?php if ($utils->isFriendly()) { echo “The time is now “ . date(); } else { echo “I will not give you the time of day”; } ?> <hr> </body> </html>
  • 7. Another example – harder to read <?php include “utilities.php”; ?> <html> <head>Test page</head> <body> <?php if ($utils->isFriendly()) { echo “The time is now “ . date(); } else { ?> <i>I will not give you the time of day!</i> <?php } ?> <hr> </body> </html>
  • 8. More PHP language details  Variables are implicitly typed  This is good  This is bad  Variables start with $  All get/post variables automatically defined  With most default server settings  With an inline directive if need be
  • 9. Defined variable example  foo.html: <html><head></head><body> <form submit=“getFoo.php”> Enter your name: <input type=“text” name=“username”> <input type=“submit”> </body></html>  getFoo.php: <html><head></head></body> Your name is <?php if (!strcmp($username)) { echo $username; } else { echo “not given”; } ?> !<br> </body></html>
  • 10. Function list examples  http://www.php.net/manual/en/function.strlen. php  All string functions  Some are “obvious” to c programmers  strlen, printf, fprintf, strpos  Some are web tailored  htmlentities, htmlspecialchars  Others are new (hacky)  addcslashes, explode, soundex, quotemeta, …
  • 11. Classes  OOP  Class structures will be defined, helping integration with other apps and work together  APIs followed by implementation  Inheritance  Object serialization  “Magic functions”
  • 12. Class example class Cart { var $items; // Items in our shopping cart // Add $num articles of $artnr to the cart function add_item ($artnr, $num) { $this->items[$artnr] += $num; } // Take $num articles of $artnr out of the cart function remove_item ($artnr, $num) { if ($this->items[$artnr] > $num) { $this->items[$artnr] -= $num; return true; } else { return false; } } }
  • 13. Inheritance example Class ParentObject { var $value; function ParentObject() { $this->value = 42; } } class MemberObject extends ParentObject { var $string; function MemberObject() { $this->string = "This is a test string."; $this->ParentObject(); } } class ObjTest { var $ObjPointer; function ObjTest() { $tmp = new MemberObject; $this->ObjPointer = $tmp; } } $object = new ObjTest; echo "String Contents: " . $object->ObjPointer->string . "n"; echo "Value Contents: " . $object->ObjPointer->value . "n";
  • 14. Back to being hacky…  “->” is NOT the same thing as it is in c++  No pointers in PHP  ONLY a member operator  Oh, you wanted pointers?  Variable variables  Yeah, you heard right  Don’t get me started…
  • 15. Variable variables and classes example class a { var $b; } $object = new a; $object->b = "hello"; $member_name = 'b'; echo $object->$member_name; $object->$member_name = " world"; echo $object->$member_name;
  • 16. Resources  http://www.php.net  http://www.w3schools.com