1 / 28

Digital Media Technology

Digital Media Technology. Week 9. PHP. Interactive and dynamic webpages Stored in a file with .php extension Code surrounded by <?php and ?> Variables start with a dollar sign, e.g. $name Number and strings Operators: + - * / PHP: hypertext preprocessor. Examples. Search engine

gaurav
Download Presentation

Digital Media Technology

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. Digital Media Technology Week 9

  2. PHP • Interactive and dynamic webpages • Stored in a file with .php extension • Code surrounded by <?php and ?> • Variables start with a dollar sign, e.g. $name • Number and strings • Operators: + - * / • PHP: hypertext preprocessor

  3. Examples • Search engine • Index of names • Web form for the creation of TEI documents

  4. Interactive Website HTML form PHPscript User information

  5. Validation of user input: example read input contains ‘@’ ? N Y write ‘email is correct’ write ‘email is not valid’

  6. HTML Form Elements <input type="text"</input> <input type="submit" value=" GO ">

  7. A Form in HTML <html> <head> <title>Databases and Webprogramming</title> </head> <body bgcolor="#99CCFF" text="#000000"> <form action="action.php" method="get"> Enter e-mail address : <br><input type="text" name="email" size="25"> <BR> <input type="submit" value=“CHECK!"> </p> </form> </body> </html>

  8. method=“get” : http://132.229.155.189/2007-2008/ action.php?email=info@leidenuniv.nl method=“post” : http://132.229.155.189/2007-2008/action.php

  9. A Form in HTML <html> <head> <title>Databases and Webprogramming</title> </head> <body bgcolor="#99CCFF" text="#000000"> <form action="action.php" method="get"> Enter e-mail address : <br><input type="text" name="email" size="25"> <BR> <input type="submit" value=“CHECK!"> </p> </form> </body> </html>

  10. Form data processed by PHP script • A so-called array will be created, depending on the method specified:$_GET or $_POST ; • Names specified can be used to refer to the values, e.g.:$_GET[“email”] ; $_POST[“email”] ;

  11. action.php : <html><head><title>DBWP</title></head> <body bgcolor="#99CCFF" text="#000000"> <?php $name = $_GET[“name”] ; print "<p>Welcome, $name !</p>" ; ?> </body> </html>

  12. Conditional Structures: Selection if ( condition ) { [ code block 1 ] } else { [ code block 2 ] }

  13. Conditional Structures: Selection $email = “info@leidenuniv.nl” ; if ( preg_match( “/@/”, $email) ) { print “Email is correct.” ; } else { print “Email is not valid. ; }

  14. Multiple choices read language English? N Y German? Write ‘Welcome!’ Y N French? Write ‘Wil-kommen!’

  15. Conditional Structures: Selection if ( condition ) { [ code block 1 ] } elseif ( condition ) { [ code block 2 ] } else { [ code block 3 ] }

  16. HTML Pull-down menu <select> <option>Select...</option><option value="">option 1</option><option value="">option 2</option></select>

  17. Pull-down menus <form action=“welcome.php" method="get"> <select name="language"> <option> -- Choose a language -- </option> <option value="dut">Nederlands</option> <option value="eng">English</option> <option value="fre">Français</option> <option value="ger">Deutsch</option> <option value="ita">Italiano</option> </select> <BR> <input type="submit" value="GO!"> </p> </form> this file in a browser

  18. $language = $_GET["language"] ; if ( $language == "dut“ ) { print "Welkom op deze website!"; } elseif ( $language == “eng" ) { print "Welcome to this website!"; }elseif ( $language == “fre" ) { print "Bienvenue sur le site!"; } elseif ( $language == “ger" ) { print "Willkommen auf der Website!"; } elseif ( $language == “ita" ) { print "Benvenuto al questo site!"; } else { print "Please choose a language first!"; }

  19. Assignment 2

  20. $titles = array ("Waiting for Godot", "Endgame", "Happy Days", “Krapp’s Last Tape" ); $title = "Waiting for Godot";

  21. Arrays • Used to define a collection / a list • Can be declared with the array()function <?php $titles = array ("The Life of Dr. Boerhaave", "First Principles of Typography", "Florentissima Brittanniae Urbs ", "Digital Access to Book Trade Archives" ) ; ?>

  22. Use of the array() function in this way will create an automatic index

  23. Addressing elements in the array <? $books = array ( "The Life of Dr. Boerhaave", "First Principles of Typography", "Florentissima Brittanniae Urbs", "A relation of a Voyage to the Army") ; print $books[1] ?>

  24. An indexed array : $capitals = array( "Italy"=> "Rome", "Luxembourg"=> "Luxembourg", "Belgium"=> "Brussels", "Denmark"=> “Copenhagen", "Finland"=> "Helsinki", "France"=> "Paris", "Slovakia"=> "Bratislava", "Slovenia"=> "Ljubljana", "Germany"=> "Berlin” ) ;

  25. Addressing an element in an indexed array : $capitals = array( "Italy"=> "Rome", "Luxembourg"=> "Luxembourg", "Belgium"=> "Brussels” ) ; print $capitals["Italy"] ; // this will print "Rome"

  26. Counting the number of elements in an array <? $books = array ("The Life of Dr. Boerhaave", "First Principles of Typography", "Florentissima Brittanniae Urbs", "Digital Acces to Booktrade Archives") ; $number = count($books) ; ?>

  27. Navigating arrays $books = array("Heart of Darkness", "The Picture of Dorian Grey", "The Last September" ); foreach ($books as $b) { print " <p> $b </p> “ ; }

  28. Navigating indexed arrays <? $apl_books = array ( "APL-1" => "The Life of Dr. Boerhaave", "APL-2" => "First Principles of Typography" ) ; foreach ($apl_books as $number => $title) { print “<p>Number $number: <b> $title </b> </p.” ;}

More Related