PHP SOLUTIONS: DYNAMIC WEB DESIGN (Windows 2003 server web) MADE EASY Chapter

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Chapter 14 explains dates in PHP and MySQL in detail, but let s take a quick look at what s happening here. The core part of the code is this line: echo date(’Y'); This displays the year using four digits. Make sure you use an uppercase Y. If you use a lowercase y instead, only the final two digits of the year will be displayed. The reason for the preceding line is because of changes to the way that PHP handles dates. Since PHP 5.1.0, PHP requires a valid time-zone setting. This should be set in php.ini, but if your hosting company forgets to do this, you may end up with ugly error messages in your page. Using ini_set() in a script like this is good insurance against this happening. It also allows you to override the hosting company setting, so this is particularly convenient if your host is in a different time zone from your own. I live in London, so the second argument for ini_set() is ‘Europe/London’. Check the time zone for where you live at www.php.net/manual/en/timezones.php. The date.timezone setting works only in PHP 5.1.0 and above. However, ini_set() silently ignores any settings it doesn t recognize, so you can use this setting safely on older versions of PHP. 3. Save footer.inc.php and load index.php into a browser. The copyright notice at the foot of the page should look the same as before unless, of course, you re reading this in 2007 or later, in which case the current year will be displayed. 4. Copyright notices normally cover a range of years, indicating when a site was first launched. To improve the copyright notice, you need to know two things: the start year and the current year. If both years are the same, you need to display only the current year; if they re different, you need to display both with a hyphen between them. It s a simple if… else situation. Change the code in footer.inc.php like this:

As in PHP Solution 4-4, I ve used curly braces around the variables in line 11 because they re in a double-quoted string that contains no whitespace. Since hyphens aren t
We recommend high quality webhost to host and run your jsp application: christian web host services.

Leave a Reply