eg-259:lecture16
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
eg-259:lecture16 [2012/03/13 19:32] – eechris | eg-259:lecture16 [2013/03/08 18:03] (current) – [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 | + | **Supplementary Material** |
+ | |||
+ | Provided for Reference. This material is no longer taught | ||
**Lecturer**: | **Lecturer**: | ||
Line 47: | Line 49: | ||
//At the end of this lecture you should be able to answer these questions//: | //At the end of this lecture you should be able to answer these questions//: | ||
- | - How Does a Web server determine whether a requested document includes PHP code | + | - How does a web server determine whether a requested document includes PHP code |
- What are the two modes of the PHP processor? | - What are the two modes of the PHP processor? | ||
- What are the syntax and semantics of the include construct? | - What are the syntax and semantics of the include construct? | ||
Line 246: | Line 248: | ||
---- | ---- | ||
* This shorthand should only be used for printing variables or with functions that return a string. | * This shorthand should only be used for printing variables or with functions that return a string. | ||
- | * The short syntax only works with the [[http:// | + | * The short syntax only works with the [[http:// |
===== Hello World (PHP) ===== | ===== Hello World (PHP) ===== | ||
Line 252: | Line 254: | ||
* PHP code is placed in the body of an HTML document | * PHP code is placed in the body of an HTML document | ||
<code html> | <code html> | ||
- | | + | <!DOCTYPE |
- | < | + | <html lang=" |
- | < | + | |
- | </ | + | < |
- | < | + | |
- | <?php | + | </ |
- | | + | < |
- | ?> | + | <?php |
- | </ | + | print " |
- | </ | + | ?> |
+ | </ | ||
+ | </ | ||
</ | </ | ||
Line 286: | Line 290: | ||
<code php> | <code php> | ||
- | <?php echo("<? | + | < |
- | < | + | |
- | " | + | |
<!-- today.php - A simple example to illustrate a PHP document --> | <!-- today.php - A simple example to illustrate a PHP document --> | ||
- | < | + | <html lang=" |
- | < | + | < |
+ | <meta charset=" | ||
+ | | ||
</ | </ | ||
< | < | ||
Line 304: | Line 308: | ||
</p> | </p> | ||
</ | </ | ||
- | </ | + | </ |
</ | </ | ||
Line 311: | Line 315: | ||
{{eg-259: | {{eg-259: | ||
- | <note warning> | ||
- | The first line of the code | ||
- | <code php> | ||
- | <?php echo("<? | ||
- | </ | ||
- | Is necessary to protect the XML declaration (needed for valid HTML) | ||
- | <code html> | ||
- | <?xml version=" | ||
- | </ | ||
- | 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: | ||
- | </ | ||
Line 379: | Line 370: | ||
* Code: | * Code: | ||
<code php> | <code php> | ||
- | <?php echo("<? | + | < |
- | < | + | |
- | " | + | |
<!-- powers.php | <!-- powers.php | ||
An example to illustrate loops and arithmetic | An example to illustrate loops and arithmetic | ||
| | ||
- | < | + | <html lang=" |
- | < | + | < |
+ | <meta charset=" | ||
+ | | ||
</ | </ | ||
< | < | ||
Line 412: | Line 403: | ||
</ | </ | ||
</ | </ | ||
- | </ | + | </ |
</ | </ | ||
Line 444: | Line 436: | ||
---- | ---- | ||
- | < | + | < |
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