Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Some Variations on Date Display 2 Print HTML Code What PHP prints will be placed into the file, and then the file is sent to the web client to be rendered.

Similar presentations


Presentation on theme: "1 Some Variations on Date Display 2 Print HTML Code What PHP prints will be placed into the file, and then the file is sent to the web client to be rendered."— Presentation transcript:

1

2 1 Some Variations on Date Display

3 2 Print HTML Code What PHP prints will be placed into the file, and then the file is sent to the web client to be rendered. Thus PHP can write anything that the web client will understand. In the above example, it is writing HTML. It writes a bold tag, then the date, then a closing bold tag. Note that if we want to print something as is (e.g. ), we put it in quotation marks. (That’s called a literal.)

4 3 Result of PHP writing HTML bold tags around the date.

5 4 Having PHP write HTML tags with attributes Next let us write the code that displays an image corresponding to the day of the week. The HTML we want written is or etc. The PHP code date(‘l’) will take care of the day of the week. (That’s a small ell.) The real problem is that the PHP code requires quotation marks and the desired HTML code also has quotation marks and we need to keep these distinct.

6 5 Escape sequences To distinguish HTML quotes from PHP quotes, we use what is called an escape sequence. The HTML quotes are preceded by a back slash (\”). The back slash now also becomes special and so if we want a back slash we have to write \\. (For other escape sequences, see column 1 of the PHP 4 Reference Card (Gould) under special characters.)

7 6 Rules of thumb for quotes In an escape sequence, the backslash always precedes the quote. –(Some people want to reverse the order for a closing quote, but that’s wrong.) The overall number of quotes must be even. The overall number of \” must also be even. Occurrences of \” must always be inside regular quotes.

8 7 PHP writing a image tag

9 8 The result of PHP writing a image tag

10 9 Following the rules print "<img src=\"act_"; print date('l'); print ".gif\" width=\"50px\" />"; Note in the above example –The back slashes are always before the quotes –The overall number of quotes is 8 (which is even) –The overall number of \” is 4 (which is even) –The \” are always inside pairs of regular quotes

11 10 Another approach is to place the PHP code right in the middle of an HTML tag.

12 11 The other approach gives the same result.

13 12 PHP can also write JavaScript

14 13 “I can cause accidents, too” Missing semicolon

15 14 Do not become obsessed with the line you are told the error is on. Missing quote

16 15 Errors can occur at different stages. Missing \” Error is not in PHP but in the HTML that was written. Look for mistake by viewing the source.

17 16 The PHP was OK, but it did not write good HTML. Missing quote in HTML


Download ppt "1 Some Variations on Date Display 2 Print HTML Code What PHP prints will be placed into the file, and then the file is sent to the web client to be rendered."

Similar presentations


Ads by Google