Category Archives: snippets

PHP Get monday, sunday, last monday & last sunday

A function I’ve put togheter for a work-related project to get date of monday, sunday, last monday & last sunday.. Might add in next monday and sunday later.


/**
* Get Mondays and Sundays
*
* Get monday, sunday, last monday & last sunday
* Example usage:
* // to retreive the dates using today as starting point
* $mondaysAndSundays = getMondaysAndSundays();
* // to retreive the dates using a custom date as starting point
* $mondaysAndSundays = getMondaysAndSundays('1987-04-14');
*
* @param date $offset Provide a date from where to calculate from in strtotime() translatable format. If none is given, today's date will be used.
*
* @return array
*
*/
function getMondaysAndSundays($offset=false)
{

if(!$offset) $offset = strtotime(date('Y-m-d'));
else $offset = strtotime($offset);

// this week
if(date('w',$offset) == 1)
{
$mas['monday'] = date('Y-m-d',$offset);
}
else
{
$mas['monday'] = date('Y-m-d',strtotime("last Monday",$offset));
}

if(date('w',$offset) == 6)
{
$mas['sunday'] = date('Y-m-d',$offset);
}
else
{
$mas['sunday'] = date('Y-m-d',strtotime("next Sunday",$offset));
}

// last week
if(date('w',$offset) == 1)
{
$mas['lastmonday'] =  date('Y-m-d',strtotime('-1 week',$offset));
}
else
{
$mas['lastmonday'] = date('Y-m-d',strtotime('-1 week', strtotime(date('Y-m-d',strtotime("last Monday",$offset)))));
}

if(date('w') == 6)
{
$mas['lastsunday'] = date('Y-m-d',strtotime('-1 week',$offset));
}
else
{
$mas['lastsunday'] = date('Y-m-d',strtotime("last Sunday",$offset));
}

return $mas;
}

always_populate_raw_post_data disabled? here’s a workaround

Since HostGator does not support changing the value of always_populate_raw_post_data in PHP to “1″, I had to find a work around. After spending an hour Googling my issue and it turning zero-dot-zero results I was forced into being creative.

Appearantly you can use the input wrappers to go around this setting. Perhaps you could find this useful in the future

[snippet]<php
if(!$HTTP_RAW_POST_DATA){
$HTTP_RAW_POST_DATA = file_get_contents(‘php://input’);
if(empty($HTTP_RAW_POST_DATA))
{
// die here
}
}
[/snippet]

All cities of Belgium with postal code and GPS location

Although, to you foreigners, it may seem like there is not going to be a Belgium in the near future …

For a project of mine, I had to find a database that contained all cities of Belgium with their postal codes and GPS locations (longitude & latitude). Since I couldn’t find such a database (or I had to pay too f***ing much) I decided to create one myself.

Since I’m such a commie, I’ve decided to share this database with anyone that needs it! Please refer to this page to download the database. At this time it’s only available in Dutch. Maybe some day I’ll take the time to translate it into english. Maybe some cash would make me work faster? Send your donations to PayPal address: thomas@rdlt.com …

Download database of all cities in Belgium with postal code and GPS location!

Download een database met alle steden in België met postcode en GPS locatie!

boitier.jpg