Skip to content

Instantly share code, notes, and snippets.

@blar
blar / gist:6791278
Last active December 24, 2015 11:29
DateFormatter
<?php
date_default_timezone_set('Europe/Berlin');
Locale::setDefault('de_DE');
$formatter = new IntlDateFormatter(NULL, IntlDateFormatter::FULL, IntlDateFormatter::FULL);
var_dump($formatter->format(new DateTime()));
$formatter = new IntlDateFormatter(NULL, IntlDateFormatter::FULL, IntlDateFormatter::LONG);
@blar
blar / gist:6781316
Last active December 24, 2015 09:59
Der BreakIterator
<?php
Locale::setDefault('de_DE');
$iterator = IntlBreakIterator::createSentenceInstance(NULL);
$iterator->setText('Das ist ein Test, wie ein Text in mehrere Teile zerlegt werden soll. Auch ein Datum wie 20.04.2001 oder auch 24. Dezember soll nicht falsch umgebrochen werden. iPhone oder iPad – am besten beides!');
foreach($iterator->getPartsIterator() as $item) {
var_dump($item);
}
<?php
class A {
private $b;
public function __construct($b) {
$this->b = $b;
}
@blar
blar / gist:6663769
Last active December 23, 2015 16:39
Login bei Facebook per OAuth 2 und API-Anfragen per WADL
<?php
namespace Modules\Account\Controllers;
use MVC\Controllers\RestController,
Blar\HTTP\Url,
Blar\OAuth,
Blar\Wadl,
Blar\DateTime,
Modules\Account\Models\UserModel,
(function(a,b){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|
blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|
iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|
opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|
series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|
windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|
50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|
amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|
avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|
capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|
<?php
namespace Modules\Account\Controllers;
use MVC\Controllers\RestController,
Modules\Account\Models\UserModel,
Modules\Account\Models\UserServiceModel,
Blar\Wadl;
class ImportController extends RestController {
#!/usr/bin/env php
<?php
date_default_timezone_set('Europe/Berlin');
$filename = $_SERVER['argv'][1];
$filenames = array($filename);
$fileInfo = new FInfo(FILEINFO_MIME);
while($filename = array_shift($filenames)) {
@blar
blar / gist:5776456
Created June 13, 2013 19:09
DatePeriod
<?php
namespace Blar\Calendar;
use Iterator,
LimitIterator,
DateTime,
DateInterval,
DateTimeInterface;
<?php
class UploadManager {
public $fields = array();
public function __construct($files = NULL) {
if(is_null($files)) {
$files = $_FILES;
}
<?php
class UploadManager {
public $fields = array();
public function __construct() {
$this->fields = $this->parse($_FILES);
}