1 / 33

Digital Media Technology

Digital Media Technology. Week 10. PHP. Interactive and dynamic webpages PHP: hypertext preprocessor Embedded in HTML files 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: + - * /. Examples.

deiter
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 10

  2. PHP • Interactive and dynamic webpages • PHP: hypertext preprocessor • Embedded in HTML files • 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: + - * /

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

  4. Digitale Bibliotheek Nederlandse Literatuur (DBNL) TEI PHP

  5. Crowdsourcing

  6. Human Programmer Programming language, e.g. PHP Language interpreter Computer Machine Language 0101100101010

  7. Computer languages are artificial languages: Grammar & Syntax first, then usage. Natural languages: Usage, grammars are reconstructed • Strictness and consistency is necessary for development of interpreters

  8. Programming takes place in two steps: • Algorithmic design • Coding • Algorithms can be visualised in Program Structure Diagrams

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

  10. HTML form PHPscript User information

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

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

  13. method=“get” : http://www.bookandbyte.org/2012-2013/ action.php?email=info@leidenuniv.nl method=“post” : http://www.bookandbyte.org/2011-2012/action.php

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

  15. 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”] ;

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

  17. Conditional Selection <xsl:if test="place"> <xsl:value-of select="place"/> <xsl:if test="year"> <xsl:text>, </xsl:text> </xsl:if></xsl:if> <xsl:if test=“year"> <xsl:value-of select=“year"/> </xsl:if>

  18. Conditions in PHP if ( condition ) { [ code block 1 ] } else { [ code block 2 ] }

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

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

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

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

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

  24. $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!"; }

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

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

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

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

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

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

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

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

  33. "We will encourage you to develop the three great virtues of a programmer: laziness, impatience, and hubris." (Larry Wall, Programming Perl)

More Related