1 / 27

Digital Media Technology

Digital Media Technology. Week 13. PHP. Dynamic and interactive webpages Embedded in HTML Server-side programming language. Variables $name = “Oscar Wilde” ; $number = 10 ;

pembroke
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 13

  2. PHP • Dynamic and interactive webpages • Embedded in HTML • Server-side programming language

  3. Variables $name = “Oscar Wilde” ; $number = 10 ; • Operators $sentence = $name . “ has written ”. $number . “ plays.” ; $half = $number / 2 ; $double = $number * 2 ;

  4. Interactive Website HTML form PHPscript User information

  5. 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>

  6. 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

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

  8. 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>

  9. Form data processed by PHP script • A so-called superglobal 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”] ;

  10. action.php : <html><head><title>DBWP</title></head> <body bgcolor="#99CCFF" text="#000000"> <?php $email = $_GET[“email”] ; print "<p>You have typed in this e-mail address: $email.</p>" ; ?> </body> </html>

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

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

  13. Conditional Structures: Selection $email = “info@leidenuniv.nl” ; if ( eregi ( “@”, $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 Form Elements <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. $titles = array ("Waiting for Godot", "Endgame", "Happy Days", “Krapp’s Last Tape" ); $title = "Waiting for Godot";

  20. 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" ) ; ?>

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

  22. 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] ?>

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

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

  25. 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) ; ?>

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

  27. 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