Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.

Similar presentations


Presentation on theme: "PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter."— Presentation transcript:

1 PHP Server-side Programming

2 PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter is built into the web server  Syntax is similar to C, Java, Perl  PHP is open source, free, available for most platforms, popular

3 What can you do with PHP  Generate content as an HTML page is loaded (generate HTML code)  Respond to a form with dynamic content  Retrieve and display information from a database

4 Where does the PHP code go?  PHP code goes into a special element type in your HTML files.  You can have multiple php elements in a page  Code in the php element is sent to the php interpreter; everything else is assumed to be content

5 HelloWorld in PHP PHP

6 Here Documents  Instead of using multiple print statements, use a here document print <<<_HTML_ … _HTML_  Everything between the two _HTML_ is printed

7 Getting Dynamic Content from a Form  Displaying form Your Name:  PHP program that responds to form <?php print "Hello, "; // Print what was submitted in the form parameter called 'user' print $_POST['user']; print "!"; ?>

8 Basics  Syntax is similar to C and perl  // /* */ and # for comments  Statements are terminated by semicolon  Whitespace insensitive  Keywords are case-insensitive

9 More Basics  Variable names same as for Java with a $ in front  can be assigned by value or by reference  Untyped  Use printf for output  Just like in C

10 Built-In Types  Primitive  boolean  integer  float  string  Compound  array (similar to hash in perl)  object - defined by a class  Special types  NULL  resource

11 Strings  Use either double or single quotes for strings  Use \ as an escape character  Strings can extend over multiple lines  Variable expansion will occur in double- quoted strings

12 String functions  trim removes leading and trailing whitespace  strlen gives number of characters in the string  == can be used to compare strings (case sensitive)  strcasecmp() compares strings ignoring case (semantics of C strcmp)  Use. for concatenation  get substrings using substr( string, start, length)

13 Numbers  PHP distinguishes between integer and floating point values  Usual set of arithmetic operations and assignment operators  integer division can give floating point result  Usual set of mathematical functions  Other functions for things like formatting, type conversion, …

14 Booleans  False values are 0, 0.0, "0", "", false, NULL, array with 0 elements, object with 0 member variables  everything else is true  Usual set of comparison operators ( = >)  work with strings  Usual set of logical operators (! && ||)

15 Control Statements  Selection if ( cond) { … } elseif (cond2) { …} … else { … }  also switch  Loops while (cond) { … } do { … } while( cond); for (init; cond; update) { … } foreach() { … }

16 Coming later  Arrays  Objects  Functions  Interacting with the OS  Form processing  Using databases

17 Sources  Learning PHP 5 by David Sklar  Programming PHP by Rasmus Ledorf and Kevin Tatroe  PHP home page  http://www.php.net/


Download ppt "PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter."

Similar presentations


Ads by Google