Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scott Marino MSMIS Summer Session 1 - 2001 Web Site Design and Authoring Session 13 Scott Marino.

Similar presentations


Presentation on theme: "Scott Marino MSMIS Summer Session 1 - 2001 Web Site Design and Authoring Session 13 Scott Marino."— Presentation transcript:

1 Scott Marino MSMIS Summer Session 1 - 2001 Web Site Design and Authoring Session 13 Scott Marino

2 MSMIS Summer Session 1 - 2001 Topics Introduction to PHP PHP Syntax Forms and Form Elements Numbers and Strings Conditionals and Loops Arrays and Regular Expressions

3 Scott Marino MSMIS Summer Session 1 - 2001 Introduction to PHP Originally called Personal Home Page (PHP) Now called Hypertext Preprocessor Created in 1994 as an open source project Server-Side execution Cross Platform compatible –Unix, Windows, Mac, OS/2 HTML embedded

4 Scott Marino MSMIS Summer Session 1 - 2001 Why use PHP Better, faster, and easier to learn than CGI, ASP, and JSP PHP does much more than you can do with basic HTML PHP was written specifically to create web pages –Perl, VBScript and Java were adapted to work on the web Can’t do everything that other programming languages can

5 Scott Marino MSMIS Summer Session 1 - 2001 Basic Syntax Directive to PHP to interpret the code between the tags and perform the instructions –The phpinfo function prints installation information about PHP –Every instruction ends with a semicolon Files are saved with a.php extension instead of.htm for Apache

6 Scott Marino MSMIS Summer Session 1 - 2001 Basic Syntax print(“Hello there”); –Print function to embed text or html into the web page // or # denotes a single line comment /* (several text lines) */ for commenting multiple lines

7 Scott Marino MSMIS Summer Session 1 - 2001 Basic Syntax Variable Types –Number –String –Array $num_var = 1; $float_num_var = 1.2; $string_var = “PHP is cool!”; Look at phpinfo(); for available environment variables

8 Scott Marino MSMIS Summer Session 1 - 2001 Forms and PHP PHP can access data elements from a form Instead of calling a cgi script in the form action, the action will point to a PHP page Can use both post and get methods (on the form) print(“$lname”); –Prints the PHP variable from the form field name

9 Scott Marino MSMIS Summer Session 1 - 2001 Formatting Numbers To print a $ sign, you must “escape” it –print (“total dollars = \$$total_dollars”); The printf(); function can format numbers for printing Supports mathematical precedence with the use of parenthesis Has built in functions like round(); and abs(); Can create random numbers with srand(); and rand();

10 Scott Marino MSMIS Summer Session 1 - 2001 String Formatting trim(); removes leading and trailing spaces from string fields –ltrim(); and rtrim(); functions are available $string = $astring. $bstring; $string = $astring. “ “. $bstring; urlencode(); is used to convert characters to the proper format for a url urldecode(); is used to convert an encoded url back to standard format

11 Scott Marino MSMIS Summer Session 1 - 2001 String Formatting strtok(); Creates a string from a token –$f_name = strtok($fullname, “ “); substr($string,0,10); –Parses the first 10 characters of the contents of $string starting with position 0 strlen($string); –Counts the number of characters in $string

12 Scott Marino MSMIS Summer Session 1 - 2001 Conditionals if (condition) { true action; } else { false action; } If the condition or test results in “true” then execute the “true action” else execute the “false action”

13 Scott Marino MSMIS Summer Session 1 - 2001 Conditionals if (condition) { true action; } elseif (condition) { true action; } else { false action; } The elseif allows for additional levels of conditions to be checked

14 Scott Marino MSMIS Summer Session 1 - 2001 Conditionals switch ($state) { case "AL": print ("Alabama"); break; ….. default: print(”State of Confusion"); Used for a longer list of conditions than is easily handled with elseif

15 Scott Marino MSMIS Summer Session 1 - 2001 Looping while (condition) { statements; } do { statements; } while (condition); for ($I = 1; $I <= somecount; $I++) { statements; }

16 Scott Marino MSMIS Summer Session 1 - 2001 Arrays $list = array(“apples”,”peaches”,”pears”); –Creates a simple array with elements in array positions 0,1, and 2 $list = array(1=>“apples”, 2=>”peaches”, 3=>”pears”); –Creates an indexed array with elements in array positions 1, 2, and 3 $list[] = “grapes”; –Adds element “grapes” to the end of the array

17 Scott Marino MSMIS Summer Session 1 - 2001 Regular Expressions PHP Supports Regular Expressions ereg(“pattern”,”string”); –ereg is a case sensitive match $pattern = “pattern”; $string = “string”; eregi($pattern, $string); –eregi is a case insensitive match


Download ppt "Scott Marino MSMIS Summer Session 1 - 2001 Web Site Design and Authoring Session 13 Scott Marino."

Similar presentations


Ads by Google