Skip to content

Instantly share code, notes, and snippets.

@kylekatarnls
kylekatarnls / yii2-pug-php3
Created October 24, 2017 12:42
Pg-php 3 for Yii2 adapter
<?php
namespace rmrevin\yii\pug;
use Pug\Pug;
use Yii;
use yii\base\View;
use yii\helpers\FileHelper;
/**
@kylekatarnls
kylekatarnls / silex-pug.php
Created December 12, 2017 15:38
Use Pug in a Silex app
<?php
// Install Pug with: composer require pug-php/pug
$app['view'] = function () {
return new Pug(array(
'cache' => './storage/cache',
'paths' => array(
// Here you can record differents root directories
// containing pug templates.
@kylekatarnls
kylekatarnls / languages.php
Last active January 8, 2019 15:03
[PHP] Langages ISO 639-1 Code, Name And Native Name; And Regions ISO 3166-2 Codes
<?php return [
'ab' => [
'isoName' => 'Abkhazian',
'nativeName' => 'аҧсуа бызшәа, аҧсшәа',
],
'aa' => [
'isoName' => 'Afar',
'nativeName' => 'Afaraf',
],
'af' => [
new Date('2001-12-31T23:59:59.000000Z').toLocaleString('en-US', {
timeZone: 'Asia/Calcutta'
});
<?php
date_default_timezone_set('UTC');
<?php
$inputDateString = '2018-05-12 23:16:46.123456'; // get from DB or some API
$date = new DateTimeImmutable($inputDateString);
echo $date->format('Y-m-d\TH:i:s.u\Z');
dateString = '2018-05-12T23:16:46.123456Z'; // get from your PHP server (JSON API, data-* attribute, etc.)
date = new Date(dateString);
alert(date.toLocaleString());
<?php
$inputDateString = '2018-05-12 23:16:46.123456'; // get from DB or some API
$jsonFormat = 'Y-m-d\TH:i:s.u\Z';
$start = new DateTimeImmutable($inputDateString);
$end = $start->modify('+2 days');
echo json_encode([
'title' => 'Foobar',
'start' => $start->format($jsonFormat),
'end' => $end->format($jsonFormat),
<?php
setlocale(LC_TIME, "$lang.UTF-8", "$lang.utf8", $lang, strstr($lang, '_', true));
$utcString = '2018-05-12 23:16:46.123456';
$date = new DateTimeImmutable($utcString);
$localString = $date->setTimezone(new DateTimeZone($timezone))->format('Y-m-d H:i:s.u');
echo strftime('%x %X', strtotime($localString));
<?php
$inputDateString = '2018-05-12 23:16:46.123456';
$date = new CarbonImmutable($inputDateString);
echo $date->toJSON();