User Tools

Site Tools


eg-259:lecture16

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
eg-259:lecture16 [2012/03/13 19:38] – [Hello World (PHP)] eechriseg-259:lecture16 [2013/03/06 19:22] – [Introduction to PHP (Part 1)] eechris
Line 2: Line 2:
 ====== Introduction to PHP (Part 1) ====== ====== Introduction to PHP (Part 1) ======
  
-**Contact Hour 19**: To be discussed on Tuesday 20th March, 2012.+**Contact Hour 21**: To be discussed on Tuesday 19th March, 2013.
  
 **Lecturer**: [[C.P.Jobling@Swansea.ac.uk|Dr Chris P. Jobling]]. **Lecturer**: [[C.P.Jobling@Swansea.ac.uk|Dr Chris P. Jobling]].
Line 288: Line 288:
  
 <code php> <code php>
-<?php echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); ?>  +<!DOCTYPE html>
-<!DOCTYPE html PUBLIC "-//w3c//DTD HTML 1.1 //EN" +
- "http://www.w3.org/TR/HTML11/DTD/HTML11.dtd">+
  
 <!-- today.php - A simple example to illustrate a PHP document --> <!-- today.php - A simple example to illustrate a PHP document -->
-<html xmlns = "http://www.w3.org/1999/HTML" xml:lang="en"> +<html lang="en"> 
-  <head> <title> today.php </title>+  <head>  
 +    <meta charset="utf-8" /> 
 +    <title> today.php &ndash; A simple example to illustrate a PHP document  </title>
   </head>   </head>
   <body>   <body>
Line 306: Line 306:
     </p>     </p>
   </body>   </body>
-</html> +</html>
 </code> </code>
  
Line 313: Line 313:
 {{eg-259:l16-today.png|Result of executing PHP script today.php}} {{eg-259:l16-today.png|Result of executing PHP script today.php}}
  
-<note warning> 
-The first line of the code 
-<code php> 
-<?php echo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); ?>  
-</code> 
-Is necessary to protect the XML declaration (needed for valid HTML) 
-<code html> 
-<?xml version="1.0" encoding="utf-8"?> 
-</code> 
-from the PHP parser. The code simply asks PHP to //echo// the declaration rather than ecoding it directly in the HTML part of the script. If you do not do this you get this mysterious error message! 
- 
-**Parse error**: syntax error, unexpected T_STRING in **C:\xampp\htdocs\eg-259\examples\lecture16\today.php** on line 1 
-</note> 
    
  
Line 381: Line 368:
   * Code:   * Code:
 <code php> <code php>
-<?php echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); ?>  +<!DOCTYPE html>
-<!DOCTYPE html PUBLIC "-//w3c//DTD HTML 1.1 //EN" +
- "http://www.w3.org/TR/HTML11/DTD/HTML11.dtd">+
  
 <!-- powers.php <!-- powers.php
      An example to illustrate loops and arithmetic      An example to illustrate loops and arithmetic
      -->      -->
-<html xmlns = "http://www.w3.org/1999/HTML" xml:lang="en"> +<html lang="en"> 
-  <head> <title> powers.php </title>+  <head>  
 +    <meta charset="utf-8"> 
 +    <title> powers.php &ndash An example to illustrate loops and arithmetic </title>
   </head>   </head>
   <body>   <body>
Line 414: Line 401:
     </table>     </table>
   </body>   </body>
-</html> +</html> 
 </code> </code>
  
Line 446: Line 434:
 ---- ----
  
-<note>+<note warning>
 this is not necessarily a good idea! Notice how the end brace for the conditional is separated from the loop body by several unrelated HTML tags. This produces fragile code -- if the second set of PHP tags where removed, a syntax error would occur which might be difficult to track down. this is not necessarily a good idea! Notice how the end brace for the conditional is separated from the loop body by several unrelated HTML tags. This produces fragile code -- if the second set of PHP tags where removed, a syntax error would occur which might be difficult to track down.
-</code>+</note>
  
  
eg-259/lecture16.txt · Last modified: 2013/03/08 18:03 by eechris