Foulmouthed Foodie
Now Loading...
December 23, 2019

PHP Automatic Copyright Year

629

Having the correct current year in the footer of your website is a handy thing if you don't wish to keep manually updating it. Heres how you can have it automatically update without the needs of manual code editing.

Auto date current year

echo date("Y");

Auto date with start year

© 2008- echo date("Y");

Start date with error protection

function autoCopyright($year = 'auto'){
	if (intval($year) == 'auto'){
		$year = date('Y');
	} elseif (intval($year) == ('Y')){
		echo intval($year);
	} elseif (intval($year) < ('Y')){
		echo intval($year);
	} else {
		echo date('Y');
}

Usage

autoCopyright(); //2019
autoCopyright("2010"); // 2010 - 2019
Next Post Fluid typography goes hand in hand with responsive design
Mark Baker @theswearingwelshman Hi, Im Mark the fucking Swearing Welshman! I am a middle aged miserable git from South Wales that absolutely fuckign loves food, so much that I fucking decided to make a pissing food blog! Here you are going to find reviews and blogs as well as recipes. Eat your fucking heart out!