Automatically display the current year in footer in PHP?

By Moe Jame Share
Browse the PHP category for more tutorials

1. Regular solution (without use of PHP)

a. (Code) Open a new file or your existing footer.php file. You probably have your year dates hard coded in there:

Standard solution without dynamic generation

b. (Output) This will simply display:

Output of the Standard Solution (no php used)

2. Dynamic Solution (In-line)

a. (Code)  to display the year (using PHP inline code) is simply <?php echo date("Y"); ?>

Dynamic Solution to display the year

b. (Output)

Output of the Dynamic Solution to display the year (using PHP)

3. Dynamic Solution (as a Function) without a start date

a. (Code)  to display the year (using a function instead of in-line code):

<?php
function dynamic_date($startyear) {
if (isset($startyear)) {
echo "".$startyear."-".date("Y")."";
} else {
echo date("Y");
}
}
?>
&copy; ThinkTutorial <?php dynamic_date(); ?>

View in editor:

Function to generate the Dynamic Solution to display the year

b. (Output)

Dynamic Solution Output (without a start year defined in the function)

4. Dynamic Solution (as a Function) with a start date

a. (Code)  to display the year (using a function instead of in-line code) with a start date of “2010″ for example:

<?php
function dynamic_date($startyear) {
if (isset($startyear)) {
echo "".$startyear."-".date("Y")."";
else {
echo date("Y");
}
}
?>
&copy; ThinkTutorial <?php dynamic_date("2010"); ?>

View in editor:

Function to generate the Dynamic Solution to display the year (with start year)

b. (Output)

Output of the function to generate the Dynamic Solution to display the year (with start year)

 

Keywords

AutomaticallyDateDisplayYear

More PHP Tutorials

How to Add up numbers on PHP

How to Automatically display the current year in footer on PHP

How to Display text using a variable on PHP

How to List files in a directory on PHP

Follow us on Twitter Subscribe to our Feeds Become a Fan on Facebook

3 Responses and Counting

Guest 09.06.2010

i can has cheeseburger?


I was confused but this clears it all up, thanks :D


I need this stuff right now! Anyway, I had hard times finding the right steps but I think this worth all the long hours that I wait.


Add your comment

(Spamcheck Enabled)



New Tutorials in your inbox!

Follow Us

RSS
facebook
twitter