outline of presentation
play

Outline of Presentation Introduction A PRESENTATION BY PHP History - PowerPoint PPT Presentation

Outline of Presentation Introduction A PRESENTATION BY PHP History Variables and Expressions Control Structures Cookies Session Variables File I/O Functions and Classes Database Connectivity Comparisons


  1. Outline of Presentation � Introduction A PRESENTATION BY � PHP History � Variables and Expressions � Control Structures � Cookies � Session Variables � File I/O � Functions and Classes � Database Connectivity � Comparisons (ASP.NET & CGI) � References What is PHP? PHP Advantage � PHP is a FREE server side scripting language for � A scripting language that borrows its syntax from C, creating dynamic webpages perl and java. As such it is fairly easy to pick up � It can be embedded in HTML � Can be programmed in various styles from procedure to OOP <html> <head> � Scripts can be easily embedded into HTML to make <title>PHP Test</title> dynamic web content </head> � Runs on nearly every web server and operating with <body> very minimal if any changes being required to the PHP <?php echo '<p>Hello World</p>'; ?> code </body> � Uses ODBC, and has native drivers for MySQL, </html> Oracle, Postgres taking advantage of each database's unique features

  2. Outline of Presentation PHP History: PHP 1 and 2 � Introduction � Originated in 1995 by Rasmus Lerdorf � PHP History � Initially a simple set of perl scripts � Variables and Expressions � Zeev Suraski and Andi Gutmans, working � Control Structures together with Rasmus Lerdorf created PHP 3 in � Cookies 1997 � Session Variables � File I/O � Functions and Classes � Database Connectivity � Comparisons (ASP.NET & CGI) � References PHP History: PHP 3 PHP History: PHP 4 � In 2002 a complete rewrite of the PHP core, PHP 3 was very successful for the following now known as zend engine reasons: � Improved the performance of complex – A solid infrastructure for connecting to a variety of applications and improved the modularity of different databases,protocols, and APIs PHP's code base – An extensibility feature that attracted developers to � Support for many more web servers, HTTP add their own extension modules sessions, output buffering, more secure ways – Object oriented Syntax support and a more of handling user input and several new consistent language syntax language constructs

  3. PHP History: PHP 5 Outline of Presentation � Introduction � Released recently, offers another significant � PHP History performance improvement over php 4 with the � Variables and Expressions new ZEND 2 engine � Control Structures � Additional features such as exception handling, � Cookies and a stronger object oriented model, all the � Session Variables while being highly backward-compatible � File I/O � Functions and Classes � Database Connectivity � Comparisons (ASP.NET & CGI) � References Variables Scalar Variables � Case sensitive so $Welcome_Text is not the � A scalar variable can contain: same as $welcome_text – String $myVariable = “hello”; – Integer $myVariable = 42; � Names can contain letters, numbers and – Float $myVariable = 23.25; underscores but cannot begin with a number or underscore � Only strings in double quotes are evaluated – $myString =“hello $test”;

  4. Arrays Regular Expressions � Indexed from 0 to n-1 � Six functions that all take a regular expression string as an argument � Create array by array function – $myArray= array("Hello", "World"); – ereg: search a string for matches of reg expression � Create array by array indentifier: – eregi: case sensitive version – $myArray[] = “Hello”; MyArray[] = “World”; – ereg_replace: replaces occurrences of string with new string � An element of an array is prefixed with $ – eregi_replace: case sensitive version – $myArray[3] = ‘alpha’; $myVar = $myArray[0]; – split: returns the matches as an array of strings � Key values do not have to numeric – spliti: case sensitive version – $names = array("a"=>"Andy", "b"=>"Chris", "c"=>"Dave", "d"=>"Bill"); � eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-] +\.[a-zA-Z.]{2,5}$', $email) Outline of Presentation Control Structures - Conditionals � Introduction � if(condition){statements} � PHP History – if($number) {echo “”the number is not zero!”;} � Variables and Expressions � if(condition) {statements} else {statements} � Control Structures � if(condition) { statements } � Cookies elseif (condition) {statements} � Session Variables else {statements} � File I/O � switch(expression) {statements} � Functions and Classes � variable= (condition) ? expression1: expression2; � Database Connectivity � Comparisons (ASP.NET & CGI) � References

  5. Control Structures - Loops Outline of Presentation � Introduction � while (condition) {statements} � PHP History � do {statements} while (condition); � Variables and Expressions � for (init;condition;increment) {statements} � Control Structures � foreach (list) { statement} � Cookies � Session Variables – foreach $line (array) {echo “$line\n”;} � File I/O � Functions and Classes � Database Connectivity � Comparisons (ASP.NET & CGI) � References Cookies Outline of Presentation � Introduction � Setting Cookies � PHP History – setcookie(string CookieName, string CookieValue, int CookieExpireTime, path, domain, int secure); � Variables and Expressions – <?php setcookie("uname", $name, time()+36000); ?> � Control Structures � Cookies � Retrieving Cookies � Session Variables – $_COOKIE[“cookieName”] � File I/O – ?php if (isset($_COOKIE["uname"])) echo "Welcome " . � Functions and Classes $_COOKIE["uname"] . "!<br />"; else echo "You are not logged in!<br />"; ?> � Database Connectivity � Comparisons (ASP.NET & CGI) � References

  6. Useful Variables Examples of Variable Use � $_ENV - Contains system environment variables � Browser Example � $_GET - Contains variables in the query string, – <? "Your Browser is: including from GET forms ".$_SERVER["HTTP_USER_AGENT"] ?> � $_POST - Contains variables submitted from POST � Get and Post Example (after a post) forms – <?php echo $_POST["variableName"]; ?> � $_COOKIE - Contains all cookie variables � $_SERVER - Contains server variables, such as � SSI- Server Side Includes HTTP_USER_AGENT – <?php require("header.htm"); ?> � $_REQUEST - Contains everything in $_GET, $_POST, and $_COOKIE � $_SESSION -- Contains all registered session variables Outline of Presentation File I/O � Introduction � The fopen() function is used to open files in PHP � PHP History – If the fopen() function is unable to open the specified file, it returns 0 � Variables and Expressions – Example: � Control Structures <?php $f=fopen("file.txt","r"); ?> � Cookies � The fclose() function is used to close a file � Session Variables – <? fclose($f); ?> � The feof() function is used to determine if the end of file � File I/O is true � Functions and Classes – Note: You cannot read from files opened in w, a, and x mode! � Database Connectivity – if (feof($f)) � Comparisons (ASP.NET & CGI) echo "End of file"; � References

  7. File I/O cont’d Outline of Presentation � The fgetc() function is used to read a single character � Introduction from a file � PHP History – Reading a file character by character : � Variables and Expressions <?php � Control Structures if (!($f=fopen("welcome.txt","r"))) exit("Unable to open file."); � Cookies while (!feof($f)) � Session Variables { $x=fgetc($f); � File I/O echo $x; } � Functions and Classes fclose($f); � Database Connectivity ?> � Comparisons (ASP.NET & CGI) � References User-Defined Functions & Classes Outline of Presentation � Can create functions without predefining them unless � Introduction they are created conditionally � PHP History <?php � Variables and Expressions function foo($arg_1, $arg_2, /* ..., */ $arg_n){ echo "Example function.\n"; � Control Structures return $retval; � Cookies }?> � Session Variables � Classes can also be defined � File I/O <?php class Cart { � Functions and Classes var $items; // Global variable function add_item($artnr, $num) { � Database Connectivity $this->items[$artnr] += $num; � Comparisons (ASP.NET & CGI) }}?> � References

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend