Presentation is loading. Please wait.

Presentation is loading. Please wait.

ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.

Similar presentations


Presentation on theme: "ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints."— Presentation transcript:

1 ALBERT WAVERING BOBBY SENG

2 Week Whatever: PHP  Announcements/questions/complaints

3 What is PHP?  Server-side scripting language  PHP: Hypertext Processor  Created in 1995; current version 5.3.3  Dynamically typed (like JavaScript)  Other scripting languages:  Microsoft ASP  Adobe ColdFusion  Java (using JSP)  Ruby (using Rails)

4 PHP  Scripts are stored on a server  Interpreted on servers when a page is requested  I request example.php  Server looks up the file  PHP software processes PHP file  Output is HTML+CSS+JavaScript that is returned as the requested page

5 Real Life Examples  Facebook  ‘Compressed’ PHP  Wikipedia  Photobucket  Yahoo!  YouTube

6 PHP  Can run on most operating systems  Compatible with most servers (Apache, IIS, etc)  Lets you create dynamic webpages  Most useful when you want to insert specific custom data  Where does this data come from?  Databases!

7 PHP + MySQL  MySQL is a Structured Query Language database platform  PHP has native built-in support for MySQL  While interpreting a PHP script, PHP software can make multiple requests to multiple MySQL databases  PHP also supports many other databases

8 PHP Basics  PHP Script can contain:  HTML  CSS  JavaScript  PHP script  PHP files have extension.php  If you save them as.html, the PHP software will not process them  Closed source – your users cannot read your code (unlike JavaScript)

9 PHP Basics  PHP scripts are written inside a tag  Anything you want interpreted has to be inside these tags  Example:

10 PHP Basics  Like Java, every line in PHP ends with a semicolon;  //Single-line comments  /* Multi-line comments */

11 PHP Basics  PHP variable names are always preceded by a $  Assigning a value to a variable: $variable_name = value;  PHP variables are loosely typed  Don’t have to declare variables before using them  Can reassign variables to hold different types of values

12 PHP Basics  Variables can only include alphanumeric characters and the underscore  Variables must start with a letter or an underscore  PHP variables have a single scope, usually  Variables in functions are limited to those functions  The keyword global will use global variables inside a function

13 The global keyword

14 Operators +Addition+= -Subtraction-= *Multiplication*= /Division/= %Modulus%= ++Increment --Decrement =Assignment.=Concatenate (Strings)

15 Comparison Operators ==Equal to !=Not equal to<> <Less than <=Less than or equal to >Greater than >=Greater than or equal to

16 Logical Operators &&andAND ||orOR !not xorXOR

17 If/elseif/else if (condition) statement; elseif (condition) statement; else statement;

18 Switch switch(variable){ case a: statement; break; case b: statement; break; default: statement; }

19 Loops while (condition){ statements; } for (initialization; condition; increment){ statements; }

20 Arrays  Numerically indexed  Associatively indexed (maps)  Multidimensional (combination of one or any of the above)  Create an array with $var_name = array();  Index with $var_name[0] = assignment; or $var_name[$other_var] = assignment;

21 PHP GET  Built-in functions to get data from pages  $_GET function collects values from a form sent with method = get HTML Page: Name: Age: PHP Response: Welcome. You are years old!

22 PHP POST  Get is limited to 100 characters  Not awesome  Post has 8Mb maximum  Awesome

23 PHP Post HTML Page: Name: Age: PHP Response: Welcome. You are years old!

24 Resources  Ask Jeeves  AltaVista  http://php.net/manual/en http://php.net/manual/en  Language Reference  Your new best friend  Code examples, user questions, hints  http://www.w3schools.com/php/default.asp http://www.w3schools.com/php/default.asp

25 Homework  Create a PHP script that outputs the current date to a page, inserted among other usual HTML elements in a full page  http://php.net/manual/en/function.date.php http://php.net/manual/en/function.date.php  Use one additional construct of PHP (array, loop, if/else, etc)  Upload to your account on my server as a.php file by the start of next class  Be creative!  Databases next time (real fun starts)


Download ppt "ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints."

Similar presentations


Ads by Google