Dynamic Year Display Using PHP

posted by Ishmael Sanchez on Jun 17, 2009

Updating things like a footer or copyright statement seem trivial, but if you have a Dreamweaver site, this could mean updating hundreds or thousands of files. If you created the site correctly, all you have to do is edit one library file to update the text. However, you will still have to FTP the files and ensure nothing gets overwritten in the process. Or worse, if you failed to use templates and library files, you will have to manually edit those pages; not cool.

A better and long term solution would be to have the date dynamically created, that way you never have to worry about this update, ever. Besides saving you time and possibly headaches, it's also a good idea to use this approach because it shows a high level of professionalism and shows clients that you have the future of their site in mind.

Dreamweaver Library Item
Example of a Dreamweaver Library Item

One simple way to do this is using PHP. This code displays a copyright symbol and the current year: &copy; <?php echo date('Y') ;?>

This idea can be used with other programming languages, for example JavaScript.

On Drupal sites, you can add this code to a footer block or to the page.tpl.php. Adding the code to /admin/settings/site-information will not work because PHP isn't allowed.

Footer Output
Footer Output

Post new comment

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.

Ishmael Sanchez