Skip to content

Instantly share code, notes, and snippets.

@xappz
xappz / Validator.php
Last active April 14, 2017 10:06
Roll your own PHP validator
<?php
namespace Utils;
class Validator {
const IS_URL = 1;
const IN_ARRAY = 2;
//other constants
public static function validate($fields) {
foreach ($fields as $f) {
@xappz
xappz / dependencies.php
Last active April 26, 2017 16:15
Use php-pug with Slim3
<?php
// DIC configuration
$container = $app->getContainer();
$container['renderer'] = function ($c) {
$settings = $c->get('settings')['renderer'];
return new \Renderers\PugRenderer($settings);
};
@xappz
xappz / read-csv.php
Last active January 3, 2017 08:14
Reading CSV files in PHP
<?php
//An elegant way to read CSV data in PHP.
//Tested with PHP7
//BTW, you can quickly generate some test data at https://www.mockaroo.com/
error_reporting(-1);
const CSV_FILE = "data.csv";
const CSV_MAP = array(
'serial',
'first-name',
'last-name'