PHP on OS/2

Tom Melendez

Warpstock 2005

Agenda:

[any material that should appear in print but not on the slide]

What is PHP?

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

Your First Stop for PHP Information:

http://www.php.net

[any material that should appear in print but not on the slide]

How it Works:


When requested by the client, the PHP file is read off of the disk, interpreted, and sent to the browser as pure HTML.

No PHP code will appear in the browser if the user chose 'View Source', because that PHP code has already been interpreted and removed.
[any material that should appear in print but not on the slide]

An Example - Enabling a Web Form


<html><head><title>Form Example</title></head>
<body><h1>My Example Form</h1>
<form action="form.php" method="POST">
Name: <input type="text" name="name">
Age: <input type="text" name="age">
</form>
</body></html>
[any material that should appear in print but not on the slide]

Perl Version


  
[any material that should appear in print but not on the slide]

PHP Version


<html><head><title>Form Example</title></head>
<body><h1>My Example Form</h1>
<form action="form.php" method="POST">
Name: <input type="text" name="name">
Age: <input type="text" name="age">
</form>
<?if($_POST['name']):?>
Hi <?echo $_POST['name']?>, you are <?echo $_POST['age']?> years old
<?endif?>
</body></html>
[any material that should appear in print but not on the slide]

PHP Output


My Example Form

Name: Age:
Hi Tom, you are 29 years old


(demo #1)
[any material that should appear in print but not on the slide]

History - 10 years old!

  • Conceived in fall of 1994
  • Version 1.0: Personal Home Page Tools in early 1995
  • Version 2.0: PHP/FI 1995-1997
  • Version 3.0: PHP 1997-2000
  • Version 4.0: PHP mid-2000
  • Version 4.1: 10 Dec 2001
  • Version 4.2: 22 Apr 2002
  • Version 4.3.10: 14 Dec 2004 (Current version for OS/2)
  • Version 5.0.5: 05 Sep 2005 (Availability for OS/2???)
    [any material that should appear in print but not on the slide]
  • History: Core Development Team

  • Zeev Suraski and Andi Gutmans in Israel
  • Shane Caraveo in Vancouver
  • Stig Bakken in Norway
  • Andrei Zmievski in Lincoln, Nebraska
  • Sascha Schumann in Hagen, Germany
  • Thies C. Arntzen in Hamburg, Germany
  • Jim Winstead in Los Angeles
  • Sam Ruby in Raleigh, NC
  • Rasmus Lerdorf in San Francisco
  • (515+ people with CVS commit access)
    [any material that should appear in print but not on the slide]
  • PHP Usage Stats



  • 22,000,000+ Domains
  • 1,000,000+ Unique IPs
    [any material that should appear in print but not on the slide]
  • Platforms


  • UNIX (all variants)
  • Win32 (NT/W95/W98/W2000/XP/etc.)
  • QNX
  • MacOS
  • OSX
  • OS/2
  • BeOS
    [any material that should appear in print but not on the slide]
  • Developing with PHP


    Why developers use PHP:
  • A familiar C-like syntax
  • Easy Access to Form and Environmental data
  • Many Libraries available *
  • A large installation and developer base
  • Lots of usable code and 3rd party packages/tools
  • Excellent documentation (http://www.php.net)
  • Support available through companies such as Zend
  • The PHP License
    [any material that should appear in print but not on the slide]
  • Language and Syntax


    Embedding PHP into HTML:
  • SGML style: <? code ?>
  • XML style: <?php code ?>
  • ASP style: <% code %>
  • Javascript style: <script language="php"> code </script>

    Example:
    <HTML><HEAD>
    <TITLE>Search results for "<?php print $query; ?>"</TITLE>
    </HEAD>
    <BODY>
    [any material that should appear in print but not on the slide]
  • Language and Syntax


    Switching between HTML and PHP modes:
    <? if(strstr($HTTP_USER_AGENT,"MSIE")) { ?>
    <b>You are using Internet Explorer</b>
    <? } else { ?>
    <b>You are not using Internet Explorer</b>
    <? } ?>

    Would output to the browser:
    <b>You are not using Internet Explorer</b>
    [any material that should appear in print but not on the slide]

    C-like Syntax


       
    [any material that should appear in print but not on the slide]

    Data Types


    numbers (integers and real)
    Decimal 1234, Octal 0777, Hex 0xff
    strings
    Double-quoted "abc", single-quoted 'abc'
    booleans
    true,false

    Dynamic typing

    Arrays


    Ordered arrays

    <?
    $a
    [0] = 1;
    $a[1] = "foo";
    $a[]  = 1.57;
    ?>

    Associative arrays

    <?
    $catch_it
    ['cat'] = "mouse";
    $catch_it['dog'] = "cat";
    ?>
    [any material that should appear in print but not on the slide]

    Arrays Cont'd


    Manipulating Arrays - Lots of Functions!

    [any material that should appear in print but not on the slide]

    User-Defined Functions


    <?
    function header($title="Default Title") {?>
        <HTML><HEAD><TITLE>
        <? echo $title ?>
        </TITLE></HEAD><BODY><?
    }
    ?>

  • Mixed-mode functions
  • Pass by reference
  • Default Values for function parameters
    [any material that should appear in print but not on the slide]
  • OOP


    Defining a Class

    <?
      
    class Cart {
        var
    $items;
        function
    add_item($artnr, $num) {
            
    $this->items[$artnr] += $num;
        }  
      }
    ?>
    [any material that should appear in print but not on the slide]

    OOP Cont'd


    Inheriting a class with a Constructor

    <?
      
    class NamedCart extends Cart {
        var
    $owner;
        function
    NamedCart($name) {
            
    $this->owner = $name;
        }
      }
    ?>

    Invocation

    <?
      $cart
    = new NamedCart("PenguinGear");
      
    $cart->add_item(170923, 2);
    ?>
    [any material that should appear in print but not on the slide]