Instantly share code, notes, and snippets.

View datatables_sort_date.php
<?php
forech($datas as $data) {
echo '<td data-sort="' . date('Y-m-d', $data['unixtimefield']).'">' . date('d.m.Y', $data['unixtimefield']) . '</td>';
}
View custom-nav-walker-usage.php
<?php
// In your template files like footer.php
// The items_wrap value ('%3$s') removes the wrapping <ul>, while the custom walker (Nav_Footer_Walker) removes the <li>'s.
wp_nav_menu(array('items_wrap'=> '%3$s', 'walker' => new Nav_Footer_Walker(), 'container'=>false, 'menu_class' => '', 'theme_location'=>'footer', 'fallback_cb'=>false ));
?>
View image_encode_base64.php
<?php
$filename = 'anhaenger.jpg';
//$filename = 'anhaenger.png';
$path = 'img/' . $filename;
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
file_put_contents('base64/' . substr($filename, 0, (strrpos($filename, '.'))), $base64);
echo $base64;
View svg_from_file_with_d3.js
const fs = require('fs');
const d3 = require('d3');
const D3Node = require('d3-node');
var jsdom = require('jsdom');
const { JSDOM } = jsdom;
var contents = fs.readFileSync(__dirname + '/data/rectangle_100.svg', 'utf8');
// console.log(contents);
const dom = new JSDOM(contents);
// console.log(dom.window.document.querySelector('svg').outerHTML);
View multiple_namespaces_in_a_file.php
<?php
namespace A {
$closure = function () {
echo __NAMESPACE__;
};
}
namespace B {
$closure = function () {
View zf2_controller-with-viewHelper.php
<?php
namespace MyApp\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use \Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
class IndexController extends AbstractActionController
{
View php_baseurl.php
<?php
$baseUrl = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strpos($_SERVER['SERVER_PROTOCOL'], '/'))) . '://' . $_SERVER['SERVER_NAME'];
View js_stringToUpperFirst.js
function stringToUpperFirst(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
View ZF2_log-SQL-string-with-driver-support.php
<?php
namespace BitkornShop\Table\Basket;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\HydratingResultSet;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\AdapterAwareInterface;
/**
View zf2_short_fetch_all_tablex.php
<?php
namespace Foo;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Adapter\ParameterContainer;
class A
{