How To Display Current Year in PHP
March 1st, 2008 by Angsuman ChakrabortyThe most common use of this is to display the current year in the copyright message dynamically. Anyone who really knows PHP should be able to do it easily. However not everyone who has to use PHP knows PHP, like, for example, people using snippets in ModX or modifying templates in WordPress. Here is the code snippet for them:
<php echo date('Y') ?>
Tags: How To, Open Source Software, PHP, Programming, Web, Web 2.0, WordPress | | RSS 2.0 | Trackback this Article | Email this Article










































Add to Technorati Favorites
March 1st, 2008 at 12:25 pm
You might have better luck with the following since your PHP tag is incorrect:
March 1st, 2008 at 12:28 pm
Um er… Your comment filter killed my code so here it is:
<?php date(’Y'); ?>
March 1st, 2008 at 12:29 pm
3rd Try is the charm:
<?php date(’Y'); ?>
March 2nd, 2008 at 3:14 am
The code is correct. Semicolon is not required before ending PHP tag.
March 2nd, 2008 at 1:14 pm
You are right that the ending semi-colon is not required but the “?” is required to set off the PHP tag it won’t be parsed and will not appear as the browser will parse it as if it were an unknown HTML element.