Here’s how to calculate the days until Christmas using PHP:

$daysuntilxmas = ceil((mktime(0,0,0,12,25,date('Y')) - time()) / 86400);
echo "There are $daysuntilxmas days to Xmas!";

You can combine this with my End of the day countdown javascript to have a realtime countdown with hours, minutes, and seconds. If you do that, decrement the $daysuntilxmas by 1 since you will already be counting partial days.

Hope that helps!

 

Since posting Simple Mobile Browser Detection in PHP I have received feedback indicating that an iPad is not considered a mobile device. It ultimately depends on your definition of ‘mobile’, but I see their point in that tablets are very different from cell phones. Screen size and browser capability are pretty different between mobile phones and tablet/pads, so I can understand why you’d want to distinguish between them.

So I updated my code to detect just mobile phones:

function is_mobile_phone()
{
	$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
	$mobiles = array("iphone", "ipod", "blackberry", "nokia", "phone",
		"mobile safari", "iemobile");
	foreach($mobiles as $mobile)
	{
		if(strpos($ua,$mobile)) return true;
	}
	return false;
}

I removed ipad and kindle since those are easy to detect. I removed android, palm, and mini since some of those can be tablets. I added IEMobile for Windows phones. But the most significant change is replacing ‘mobile’ with ‘mobile safari’ and ‘iemobile’. Google had pointed out that it’s best to look for android AND mobile, but it’s just as easy to search for ‘mobile safari’. Most cell phones have a string similar to:

“Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; T-Mobile G2 Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1″

Whereas most tablets have a string resembling:

“Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10″

I came across a couple user agent strings that don’t follow these rules, but weren’t very popular devices. This should cover 95% of the cases.

 

I recently did a lot of research concerning the effects of your driving speed on your car’s fuel efficiency. I was very shocked by all the info and results I found. I was also shocked that there wasn’t 1 site that explained it all together. So, I created one:

http://www.mpgforspeed.com/

The site gives you the detailed numbers and facts, and explains why it is. As always, comments are welcome…

© 2012 ShaneLabs Suffusion theme by Sayontan Sinha