·  PHP – Introduction

 

- Info:

  - PHP is OOPL – Object Oriented Programming Language.

  - PHP stands for Personal Home Page.

  - PHP was developed by Rasmus Lerdorf for his personal use.

  - PHP was originaly just a collection of Perl/CGI scripts.

 

- Technical Info:

  - PHP is scripting language that runs on server side like PERL.

  - Program called PHP Interpreter goes through your PHP file and translates it into pure HTML file.

    Resulting HTML file is then sent back to the Client's Web Browser.

    In following example, first line, which is written in PHP, will be translated into second line, which is plain HTML:

    <body> <?php echo '<p>Hello World</p>'; ?> </body>

    <body> <p>Hello World</p> </body>

  - Here is another example of controling HTML flow using PHP.

    <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) { ?>

            <b>You are using Internet Explorer</b>

    <?php }

          else {                                                       ?>

            <font color=red>You are not using Internet Explorer</font>

    <?php }                                                            ?>

 

- PHP vs PERL:

  - PHP was developed as improvement to PERL by allowing PHP code to be embeded into HTML improving readability.

    In PERL, HTML is embeded into PERL through print function.

  - PHP was developed from ground-up with Web in mind having simple functions for most common Web tasks.

    PERL is general purpose language forcing you to write your own code or use 3rd party solutions for those tasks.

  - PHP has huge standard library which means that everybody is using the same functions for the same tasks.

    This also means that everybody can use your code without installing extra modules

 

    Test.php

    <html>

      <body>

        Today is <?php print(date('d.m.y h:i:s')); ?>

      </body>

    </html> 

 

    Test.pl

    print("Content-type: text/html\n\n");

   

    print("<html> \n");

    print("<body> \n");

    print("Today is ");

    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());

    $year += 1900;

    $mon  += 1;

    print("$mday:$mon:$year $hour:$min:$sec \n");

    print("</html> \n");

    print("</body> \n");

 

- History:

  - PHP was introduced in 1994 by Rasmus Lerdorf as a collection of freeware scripts based on Perl.

    PHP 2 version from 1995 included ability to take info submitted by web forms and convert it to usable variables.

  - ZEND Parsing Engine is highly optimized PHP execution engine created by Zeev Suraski and Andi Gutman in 1997.

    ZEND is acronym created from the names of its creators.

    ZEND is part of each modern PHP installation.

 

- Pros:

  - No Unicode support. We should all be speaking English anyhow.

  - No modules means:

    - Someone elses code will work without searching the whole www for modules it depends on.

    - Everybody is using the same functions to do the same job.

  - Web Server is executing what your PHP file contains.

    No need to keep track of source code that was used to create executable like in JAVA.

    No need to keep track when was last restart of Web Sever & which file is currently cached into memory like in PERL.

  - No namespaces. Function name is what is written in a file.

 

- Cons:

  - No namespaces, each function must have unique name.

  - Huge incoherent standard library.

  - No naming convention for function names.

  - Dot is used for both defining decimal numbers and concateneting strings resulting in unexpected behaviour.

  - Programm behaves differently depending on the extra spaces.

    $res = 1 . 2; #Same as "1"."2" resulting in "12".

    $res =  1.2 ; #Decimal number 1.2

    $res =  1 .2; #Syntax error.

    $res =  1. 2; #Syntax error.

 

- Prefered Highlighting:

  <?php  

    /*Multi line

      comment. */

    while(1==1) {

      $text = "Hello"; #Single line comment.

      print($text);

    }

  ?>

 

 

 

Red

Green

Blue

Example

 

Comment

0

128

0

#Comment.

 

Keyword

0

0

255

while

 

Variable

200

0

0

$text

 

Strings

200

0

200

"Hello"

 

Numbers

200

0

200

1

 

Other

0

0

0

print