Awesome PHP has been relocated permanently to its own Github repository. No further updates will made to this gist.
Please open an issue for any new suggestions.
<?php | |
function parseAttributes($text) { | |
$attributes = array(); | |
$pattern = '#(?(DEFINE) | |
(?<name>[a-zA-Z][a-zA-Z0-9-:]*) | |
(?<value_double>"[^"]+") | |
(?<value_single>\'[^\']+\') | |
(?<value_none>[^\s>]+) | |
(?<value>((?&value_double)|(?&value_single)|(?&value_none))) |
<?php | |
/* From: http://www.php.net/manual/en/function.str-getcsv.php#88773 and http://www.php.net/manual/en/function.str-getcsv.php#91170 */ | |
if(!function_exists('str_putcsv')) | |
{ | |
function str_putcsv($input, $delimiter = ',', $enclosure = '"') | |
{ | |
// Open a memory "file" for read/write... | |
$fp = fopen('php://temp', 'r+'); | |
// ... write the $input array to the "file" using fputcsv()... | |
fputcsv($fp, $input, $delimiter, $enclosure); |
/* | |
* RC4 symmetric cipher encryption/decryption | |
* | |
* @license Public Domain | |
* @param string key - secret key for encryption/decryption | |
* @param string str - string to be encrypted/decrypted | |
* @return string | |
*/ | |
function rc4(key, str) { | |
var s = [], j = 0, x, res = ''; |
Awesome PHP has been relocated permanently to its own Github repository. No further updates will made to this gist.
Please open an issue for any new suggestions.
<? | |
function aes128_cbc_encrypt($key, $data, $iv) { | |
if(16 !== strlen($key)) $key = hash('MD5', $key, true); | |
if(16 !== strlen($iv)) $iv = hash('MD5', $iv, true); | |
$padding = 16 - (strlen($data) % 16); | |
$data .= str_repeat(chr($padding), $padding); | |
return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv); | |
} |
<?php | |
class FlashMessages { | |
private $messages = array(); | |
private $now = false; | |
private static $instance = null; | |
private function __construct() { | |
// Save all messages | |
$this->messages = $_SESSION['flash_messages']; |
alias cd="pushd $@ > /dev/null" |