1 / 15

Introduction to PHP

Learn about PHP, a popular scripting language for web development, with insights on its capabilities, advantages, and speed compared to other languages. Explore PHP functions, file manipulation, variable handling, user-defined functions, and more. Discover the simplicity and power of integrating PHP with HTML. Get an overview of PHP's performance benefits and why it is a top choice for server-side scripting. Reference PEAR for reusable PHP components.

ruthk
Download Presentation

Introduction to PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to PHP Krerk Piromsopa. Department of Computer Engineering. Chulalongkorn University

  2. What is PHP? • PHP: Hypertext Preprocessor • A widely-used Open Source general-purpose scripting language. • Suitable for Web development / embedded into HTML. • Server-Side scripting. • Simple for a newcomer

  3. What can PHP do? • Server-side scripting (CGI or server module) • Command line scripting (Ideal for cron/task schedule) • Client-side GUI applications (PHP-GTK extension) • Usable on all major operating systems and support for most of the web servers • Support a wide range of databases • Support Java objects and CORBA

  4. Why PHP? • Performance Issue ? • The Zdnet did a evaluation and benchmarking of 4 web scripting languages. During benchmarking, the same spec and identical cpu, memory boxes were used. Under identical conditions, it was found that PHP was the fastest - about 3.7 times faster than JSP and about 1.2 times faster than ASP. Read the report at eWeek and mirror-site The benchmark results are - • PHP pumped out about 47 pages/second • Microsoft ASP pumped out about 43 pages/second • Allaire ColdFusion pumped out about 29 pages/second • Sun Java JSP pumped out about 13 pages/second • KISS policy (Keep It Simple Stupid!!)

  5. Escape between PHP and HTML 1. <? echo ("this is the simplest, an SGML processing instruction\n"); ?> 2. <?php echo("if you want to serve XML documents, do like this\n"); ?> 3. <script language="php"> echo ("some editors (like FrontPage) don't like processing instructions"); </script> 4. <% echo ("You may optionally use ASP-style tags"); %> <%= $variable; # This is a shortcut for "<%echo .." %>

  6. require() and include() Using remote files $file = fopen ("http://www.php.net/", "r"); Image Manipulate Handling File Upload PERL Style Regular Expression $string = "This is a test"; echo ereg_replace (" is", " was", $string); Variable Variable <? $home=“test”; $myvar=“home”; echo $$myvar; ?> Image Submit <input type="image" src="image.gif" name="sub"> <?= “$sub_x,$sub_y” ?> PHP Feature.

  7. <? function max($a,$b) { if ($a>$b) $max = $a; else $max = $b; return $max; } ?> <? function swap(&$a,&$b) { $tmp=$a; $a=$b; $b=$tmp; } $x=5; $y=10; swap($x,$y); ?> User define function

  8. <? function cook($time,$food="chicken"); { echo "Cook $food in $time mins"; } cook(10); cook(10,"fish" ); ?> <? $boil=“cook”; $boil(100,”water”); ?> User define function (Cont)

  9. File “common.inc” <? function Msgbox($msg,$title); echo "<P><B>$title</B></P>\n"; echo "<P>$msg</P>\n"; ?> File “sample.inc” <? require ("common.inc"); echo "Call to Msgbox"; Msgbox("Hi!!!","Greeting"); ?> Library

  10. <form method=post> <input type=text name="myvar"> </form> <?php // Global GPC echo $myvar; // PHP 3.0.2 echo $HTTP_POST_VARS["myvar"]; // PHP 4.2.0 echo $_POST["myvar"]; ?> Variable from form (POST)

  11. <? $list = `ls`; echo "<pre> $list </pre>"; ?> See system() passthru() exec() popen() escapeshellcmd(). Calling external program

  12. Header, Cookie, and session. • header('WWW-Authenticate: Negotiate'); • setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".utoronto.ca", 1); • $_SESSION['count'] = 0;

  13. Java Class Support <?php // get instance of Java class java.lang.System in PHP $system = new Java('java.lang.System'); // demonstrate property access print 'Java version='.$system->getProperty('java.version').' <br>'; print 'Java vendor=' .$system->getProperty('java.vendor').' <br>'; print 'OS='.$system->getProperty('os.name').' '. $system->getProperty('os.version').' on '. $system->getProperty('os.arch').' <br>'; // java.util.Date example $formatter = new Java('java.text.SimpleDateFormat', "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz"); print $formatter->format(new Java('java.util.Date')); ?>

  14. What is PEAR? • "The fleshy pome, or fruit, of a rosaceous tree (Pyrus communis), cultivated in many varieties in temperate climates." • PEAR is a framework and distribution system for reusable PHP components.

  15. Reference • http://www.devnetwork.net/ • http://www.php.net/ • http://pear.php.net/ • http://www.phpadvisory.com/

More Related