Skip to content

Instantly share code, notes, and snippets.

@hlev
hlev / DataUri.php
Last active November 30, 2015 20:24
A convenient class for working with Data URIs in PHP
<?php
/* The MIT License (MIT)
* Copyright (c) 2015 FlyingTopHat ([email protected])
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
@hlev
hlev / mac_regex.php
Last active May 28, 2019 23:10
PHP regexp testing for valid MAC address
<?php
/**
* To match aa:bb:cc:dd:ee:ff, aabbcddeeff, aa-bb-cc-dd-ee-ff formats in case-insensitive manner
*/
$macAddress = '2a:3b:2c:1d:44:23';
// 1
echo preg_match('/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i', $macAddress);
<?php
/**
* PHP Anonymous Object
*/
class AnObj
{
protected $methods = array();
public function __construct(array $options)