Follow Me
Subscribes Hell Buddy Solution.

Back To Top

Feel Glad finally done the Meta Tags generator and video :) project
- type: seo html - 30 September 2014 Tue @Hell Buddy

Home Message Share Translate

PHP function and date() add year Part 1

31October 2014

PHP function

function Something(){
echo "About something...";

Read the content or code / instruction -

Continue date_default_timezone_set()

Add year to current date() and then make an own function statement to run the durable program.

  1. date() and strtotime() function

    date('Y', strtotime('-2 year')) // e.g. current year minus 2 years, output: 2018

  2. string and variable concatenate

    $c = $a - $b; // it's mathematic; $c equals to $a variable minus $b

    $a.' - '.$b; // it's string; concatenate a dash between $a and $b

  3. PHP function

    create a function to make website becomes more efficiency; e.g.

    function footer(){ echo date('Y', strtotime('-2 year')); } // wrap the statement into a function

    Less codes repeating but do more functions, make the function re-usable and flexible. For example: Paste the footer() on each footer's page but only adjust on one single function page that maintain all of the pages updated!

  4. include_once() or require_once()

    Save the function to individual php file. You can use require(), include(), include_once() or require_once(), access the statement and run out the function behavior to indicate page.

    require_once('function.php' ); footer(); // you can use () parentheses with 2 single quotes

    require_once 'function.php'; footer(); // or no parentheses, but function must with parentheses

    require_once '../function.php'; footer(); // about the directory path link

Impact impression of website development

2010 © copyright by some websites footer. // Expired makes people doubt the site is an abandoned website

When I visit the other websites, I found out many footers "year" already expired. It will have a bad impression sometimes because we know many websites were abandoned and hanged on the free hosting Servers long times. People will doubt you, "Is your site still alive? 10 years ago with the outdated information ...". Expired makes people doubt the site is an abandoned website. Although the owner can show the updated or add modified post date beside the content, that would be helped. However, people want to see the newest information, once they discover expired years on footer, that much impact the site truthful and value.

open the content >>

see the code OR slideshow instruction

//example on function.php, set the timezone first


$openday date('Y'strtotime('-2 year'));
$current date('Y');

$openday.' - '.$current;


//example on footer.php or every page footer section

require_once 'function.php';


Watch next videos and relative source page(s)

tag PHP - html seo
Programming Web Development Networking FunG project

Topic Discussion:

No Topic Discuss Now...