Archive for September, 2010
PHP Looping through a range of dates
by Jay on Sep.10, 2010, under PHP
Problem:
You need to get the individual dates in a date range and store them in an arbitary data structure such as an array
Solution:
$endDate = date(“Y-m-d”, strtotime(‘yesterday’));
$startDate = ’2010-08-01′;$newDate = $startDate;
$arRangeOfDates = array();
while($newDate != $endDate) {
$newDate = date(‘Y-m-d’,strtotime(date(“Y-m-d”, strtotime($newDate)) . ” +1 day”));
$arRangeOfDates[]=$newDate;
}
The Surprising Truth About What Motivates Us
by Jay on Sep.09, 2010, under Human, Technology
Google’s Eric Schmidt posted this on his twitter account and I liked it so much, I decided to post it on yamdablam too.
PHP matching url to a domain using parse_url
by Jay on Sep.02, 2010, under Technology
Purpose:
My purpose is for a URL forwarding system whereby I need to ensure that
the target of the URL forward doesn’t match the domain the forward is being applied to.
// Take in the domain and the target url
$target=trim($_REQUEST['target']);
$domain=trim($_REQUEST['domain']); // always in the format domain.tld// Use parse_url() to get an array of the various parts of the target url
$arTargetUrl = parse_url($target);// Since were only interested in the host part of the url
$host = $arTargetUrl['host'];// Break the target up into an array based on the “.” dot
// www.url.ie becomes array(‘www’,'url’,'ie’)
$arTargetHost=explode(‘.’,$host);// Now get the size of this array
$sizeOfArray = sizeof($arTargetHost);// Since we’re only interested in the url.ie part of the host
$newHost = $arTargetHost[$sizeOfArray-2] . ‘.’ . $arTargetHost[$sizeOfArray-1];// Now compare the the newHost to the domain.
// If they’re different carry on applying the url forward
// otherwise, stop.if($newHost != $domain) {
echo ‘yay! all good’;
}
else {
echo ‘boo.. old man shouts at cloud!’;
}