1 / 16

Some Variations on Date Display

Some Variations on Date Display. 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.

bond
Download Presentation

Some Variations on Date Display

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. 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. Thus PHP can write anything that the web client will understand. In the above example, it is writing HTML. It write a bold tag <b>, then the date, then a closing bold tag </b>. Note that if we want to print something as is(e.g. <b>), we put it in quotation marks.

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

  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 <img src=“TuesdayBanner.gif” width=“650”> or <img src=“FridayBanner.gif” width=“650”> 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.

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

  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.

  7. PHP writing a image tag

  8. The result of PHP writing a image tag

  9. Following the rules print "<img src=\""; print date('l'); print "Banner.gif\" width=\"650\">"; • 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

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

  11. The other approach gives the same result.

  12. PHP can also write JavaScript

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

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

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

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

More Related