1 / 16

PHP

PHP. Teresa Worner. What is it?. P HP: H ypertext P reprocessor server-side scripting language open source cross-platform compatible with almost all servers . php .php3 . phtml. Installing PHP. http://www.php.net/manual/en/install.php XAMPP MySQL, PHP, Perl C:xampphtdocs

butch
Télécharger la présentation

PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP Teresa Worner

  2. What is it? • PHP: Hypertext Preprocessor • server-side scripting language • open source • cross-platform • compatible with almost all servers • .php .php3 .phtml

  3. Installing PHP • http://www.php.net/manual/en/install.php • XAMPP • MySQL, PHP, Perl • C:\xampp\htdocs • http://localhost/

  4. Embedding in HTML • begin/end with tags <?php ... ?> • PHP parser ignores code outside <?php ?> • PHP code run on server, result sent to client as HTML http://www.php.net/manual/en/language.basic-syntax.phpmode.php

  5. Basic Syntax • semicolons • comments // single line comment # also a single line comment /* multi-line comment */ **Note: single line comments end at the end of the line OR at the closing PHP tag – whichever comes first!

  6. Basic Syntax Cont’d • if statements if ($var) //one line elseif ($var2) //one line else //one line • print to screen echo “text”; if ($var) { //multi-line} else { //multi-line} if ($var): //multi-line else: //multi-line endif;

  7. Variables • $variableName • after $, must begin with letter or underscore, then any length of numbers/letters/underscores • predefined variables • examples: $_POST[“name”] $_GET[“name”] $_FILES[“name”]

  8. Constants • define(“constName”, assignment) • do not begin constName with $ • bool, int, float, string

  9. Types //loosely typed $var1 =“0”; $var1 += 2; //$var1 is now an integer of value 2 $var1 += 1.3; //$var1 is now a float of value 3.3 $var1 += “10 people”; //$var1 is float of value 13.3 $var1 += “hi”; //$var1 is float of value 13.3 $var2 = array(key => value, key2 => value2, );

  10. Operators • arithmetic, assignment, bitwise like C++ • comparison $a == $b //true if $a equals $b after type juggling $a === $b //true if $a equals $b and same type $a != $b //not equal after type juggling $a <> $b //not equal after type juggling $a !== $b //not equal and not same type //< > <= >=

  11. Operators Cont’d • Logical $a and $b $a && $b $a or $b $a || $b $a xor $b ! $a • string $a . $b //concatenation

  12. Operators Cont’d • array $a + $b //union of $a and $b $a == $b //true if $a and $b have same key/value pairs $a === $b //same key/value pairs, order, and types $a != $b //not equal $a <> $b //not equal $a !== $b //not identical

  13. Functions • many built-in functions: http://www.w3schools.com/php/default.asp • user declared: function funcName($var1, $var2) { return $var1 + $var2; }

  14. Sessions • session_start • starts or resumes session • default setting saves session ID in cookie • $_SESSION • superglobal array for session variables • $_SESSION[“variableName”] • session_unset • frees session variables • session_destroy • destroys session but does not free session variables or delete cookie

  15. Other Stuff • classes class ClassName { ...} • try-catch try { ... } catch(Exception $e) { ...}

  16. Useful References • http://www.w3schools.com/php/default.asp • http://www.php.net/manual/en/index.php

More Related