SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (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
 

Similar a Php

Introduction To Php For Wit2009
Introduction To Php For Wit2009Introduction To Php For Wit2009
Introduction To Php For Wit2009cwarren
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. wahidullah mudaser
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.pptJamers2
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpointwebhostingguy
 
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.3Jeremy Coates
 
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
 
Intro to php
Intro to phpIntro to php
Intro to phpSp Singh
 
Cakefest 2010: API Development
Cakefest 2010: API DevelopmentCakefest 2010: API Development
Cakefest 2010: API DevelopmentAndrew Curioso
 
Phpspec tips&amp;tricks
Phpspec tips&amp;tricksPhpspec tips&amp;tricks
Phpspec tips&amp;tricksFilip Golonka
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 

Similar a 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 (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 i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
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
 

Más de 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
 

Último

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

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