Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Create A PHP Variable Which Changes The Color Of The Background Weekly

Create A PHP Variable Which Changes The Color Of The Background Weekly

Problem

I would like to create a Php Variable which I can echo to change the color of the background weekly.

Here is what I had reached so far

I only managed to make the colors change daily, but i don't know how can I make the colors change weekly instead.

The second thing is that I need to make the colors of each first and last day of the month the color should be pink.

Any help would be very very much appreciated!

Problem courtesy of: Hamza Abd Elwahab

Solution

You can use this to change the color every week:

$today = date("W");

$today will be a value between 1 and 52, so you'll have every week of the year covered

date("t") returns the number of days of the current month

So to check if it's the first or last day, you can use this:

$LastDayOfMonth = date("Y-m-t");
$FirstDayOfMonth = date("Y-m-01");

So to put it all together, you could do it like this:

date_default_timezone_set('EST');
$today = date("W");
switch ($today) {
    case 1:
        $color = "the color you want";
        break;
    case 2:
        $color = "the color you want";
        break;
    case 3:
        $color = "the color you want";
        break;
    // All the other cases here...
}

$CurrentDate = date("Y-m-d");
$LastDayOfMonth = date("Y-m-t");
$FirstDayOfMonth = date("Y-m-1");

if ($CurrentDate == $LastDayOfMonth || $CurrentDate == $FirstDayOfMonth ) {
    $color = "the pink rgb-code";
}
Solution courtesy of: Bjorn Smeets

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

Create A PHP Variable Which Changes The Color Of The Background Weekly

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×