php tutorial_handout

Reviews
Shared by: Shariq Bashir
Tags
Stats
views:
18
rating:
not rated
reviews:
0
posted:
9/4/2009
language:
pages:
0
CS Learning Centre PHP Tutorial Introduction ⇨ ⇨ Based on PHP and MySQL Web Development, Third Edition (Available as CS eBook from Dal Library) Other eBooks from Dal Library Learning PHP 5 PHP Cookbook ⇨ ⇨ ⇨ For Online resources, google “PHP” 1 Table of Contents ⇨ ⇨ ⇨ ⇨ ⇨ ⇨ Embedding PHP Variables Operators and Control Structures Array Function Session Control (Using Cookie) Embedding PHP in HTML ⇨ Insert PHP tag inside HTML file (with .php extension XML Style ⇨ ⇨ ⇨ Short Style (Need to be enabled) Script Style ⇨ ASP Style (Need to be enabled) <% PHP statement; %> ⇨ Dynamic Content function('argument'); ⇨ Note: argument is in string 2 Variables ⇨ ⇨ Do not require to declare variable type Variable variables Constants Accessing form variables (field=tireqty) Short style (requires register_globals) $tieryqty $varname = 'tireqty'; $$varname = 5; define('TIREPRICE', 100); ⇨ ⇨ ⇨ ⇨ ⇨ Medium style $_POST['tireqty'] or $_GET['tireqty'] Long style $HTTP_POST_VARS['tireqty'] Operators and Control Structures ⇨ ⇨ ⇨ Pretty much same as in other programming languages (C, Java, etc.) Break statements are also same (continue, break), except it provides exit statement to break out of the script Alternative control structure syntex if( $totalqty == 0): echo 'You did not order anything on the previous page!
'; exit; endif; 3 Array ⇨ ⇨ Create an array Automatically generate sequnces of number, character Accessing element Array with different indices Assign key and value to variables $products = array ('Tires', 'Oil', 'Engine'); $numbers = range (1,10,2); //last parameter optional(Indicate step) ⇨ ⇨ ⇨ $products[0] $prices = array( 'Tires'=>100, 'Oil'=>10, 'Spark Plugs'=>4 ); list( $product, $price ) = each( $prices ); Array (Cont'd) ⇨ Multidimensional Array ($products[row][column] $products = array( array( 'Code' => 'TIR', 'Description' => 'Tires', 'Price' => 100 ), array( 'Code' => 'OIL', 'Description' => 'Oil', 'Price' => 10 ), array( 'Code' => 'SPK', 'Description' => 'Spark Plugs', 'Price' =>4 ) ); 4 Function ⇨ New function function my_function() { echo 'My function was called'; } ⇨ Calling function my_function(); Function (Cont'd) ⇨ Using argument Should reset the argument if it is an array The next command gets next element of arg The current command gets current element Ex. function create_table2( $data, $border = 1, $cellpadding = 4, $cellspacing = 4 ) { echo ""; reset($data); $value = current($data); while ($value) { echo "\n"; $value = next($data); } echo '
$value
'; } ⇨ ⇨ ⇨ ⇨ 5 Session Control (Using Cookie) ⇨ Manually setting Cookie in PHP bool setcookie (string name [, string value [, int expire [, string path [, string domain [, int secure]]]]]) Ex. setcookie ('mycookie', 'value'); ⇨ Using Cookie with Sessions Get session cookie parameters session_get_cookie_params() ⇨ Set session cookie parameters session_set_cookie_params($lifetime, $path, $domain [, $secure]); ⇨ Session Control (Cont'd) ⇨ Starting Session (Must be declared at the beginning of the file) Registering Session variables Unsetting variables Single variable unset($_SESSION['myvar']); session_start(); ⇨ ⇨ $_SESSION['myvar'] = 5; ⇨ ⇨ All variables $_SESSION=array(); ⇨ Destroying session session_destroy(); 6 Session Control (Example) ⇨ Begin session '; ?> Next page Session Control (Example) ⇨ Get the variable and unset it '; unset($_SESSION['sess_var']); ?> Next page 7 Session Control (Example ⇨ End session '; session_destroy(); ?> 8

Related docs
PHP
Views: 1176  |  Downloads: 153
Session in PHP
Views: 44  |  Downloads: 6
about php
Views: 11  |  Downloads: 1
PHP AND AJAX
Views: 508  |  Downloads: 143
Tutorial PHP
Views: 107  |  Downloads: 18
php
Views: 47  |  Downloads: 3
premium docs
Other docs by Shariq Bashir
INTRODUCTION TO J2EE
Views: 129  |  Downloads: 17
IntroductionTo.NET for J2EE
Views: 46  |  Downloads: 7
Introduction to J2EE CA
Views: 97  |  Downloads: 24
J2EE Architectural Guidline
Views: 95  |  Downloads: 12
J2ME Introduction Configurations
Views: 110  |  Downloads: 18
J2ME step by step
Views: 442  |  Downloads: 48
Introduction to J2ME and KVM
Views: 81  |  Downloads: 6
J2ME Basics
Views: 201  |  Downloads: 33
Introduction to Gaming with J2ME
Views: 139  |  Downloads: 15
Introduction to J2ME
Views: 210  |  Downloads: 25
Brief Introduction to Secure SMS in MIDP
Views: 421  |  Downloads: 41
Introduction of MMS in J2ME
Views: 198  |  Downloads: 15
XML programming in JAVA
Views: 146  |  Downloads: 21
Java PDF Converter
Views: 108  |  Downloads: 3
Java Basics
Views: 602  |  Downloads: 97