=")) { $bytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM); $success = true; } /* There are no secure random data sources available. Fix your * system! */ if($success === false) { throw new Exception("No secure sources for random bytes found. Install the OpenSSL or mcrypt extension."); } return $bytes; } } function extract_globals() { $vars = array(); foreach($GLOBALS as $key => $value){ $vars[] = "$".$key; } return "global " . join(",", $vars) . ";"; } function utf8entities($utf8) { // Credits to silverbeat@gmx.at (http://www.php.net/manual/en/function.htmlentities.php#96648) $encodeTags = true; $result = ''; for ($i = 0; $i < strlen($utf8); $i++) { $char = $utf8[$i]; $ascii = ord($char); if ($ascii < 128) { $result .= ($encodeTags) ? htmlentities($char) : $char; } else if ($ascii < 192) { // Do nothing. } else if ($ascii < 224) { $result .= htmlentities(substr($utf8, $i, 2), ENT_QUOTES, 'UTF-8'); $i++; } else if ($ascii < 240) { $ascii1 = ord($utf8[$i+1]); $ascii2 = ord($utf8[$i+2]); $unicode = (15 & $ascii) * 4096 + (63 & $ascii1) * 64 + (63 & $ascii2); $result .= "&#$unicode;"; $i += 2; } else if ($ascii < 248) { $ascii1 = ord($utf8[$i+1]); $ascii2 = ord($utf8[$i+2]); $ascii3 = ord($utf8[$i+3]); $unicode = (15 & $ascii) * 262144 + (63 & $ascii1) * 4096 + (63 & $ascii2) * 64 + (63 & $ascii3); $result .= "&#$unicode;"; $i += 3; } } return $result; } function clean_array($arr) { $result = array(); foreach($arr as $key => $value) { if(!empty($value)) { $result[$key] = $value; } } return $result; } function pretty_dump($input) { ob_start(); var_dump($input); $output = ob_get_contents(); ob_end_clean(); while(preg_match("/^[ ]*[ ]/m", $output) == 1) { $output = preg_replace("/^([ ]*)[ ]/m", "$1   ", $output); } $output = nl2br($output); echo($output); } function rgb_from_hex($hex) { if(strlen($hex) == 6) { $r = substr($hex, 0, 2); $g = substr($hex, 2, 2); $b = substr($hex, 4, 2); $rgb['r'] = base_convert($r, 16, 10); $rgb['g'] = base_convert($g, 16, 10); $rgb['b'] = base_convert($b, 16, 10); return $rgb; } else { return false; } } function hex_from_rgb($rgb) { if(!empty($rgb['r']) && !empty($rgb['g']) && !empty($rgb['b'])) { return base_convert($rgb['r'], 10, 16) . base_convert($rgb['g'], 10, 16) . base_convert($rgb['b'], 10, 16); } else { return false; } } function strip_tags_attr($string, $allowtags = NULL, $allowattributes = NULL) { /* Thanks to nauthiz693@gmail.com (http://www.php.net/manual/en/function.strip-tags.php#91498) */ $string = strip_tags($string,$allowtags); if (!is_null($allowattributes)) { if(!is_array($allowattributes)) { $allowattributes = explode(",",$allowattributes); } if(is_array($allowattributes)) { $allowattributes = implode(")(? 0) { $allowattributes = "(?]*>/i",create_function('$matches', 'return preg_replace("/ [^ =]*'.$allowattributes.'=(\"[^\"]*\"|\'[^\']*\')/i", "", $matches[0]);'),$string); } return $string; } function cut_text($input, $length) { if(strlen($input) > $length) { if(preg_match("/^(.{0,{$length}})\W/s", $input, $matches)) { return $matches[1] . "..."; } else { return ""; } } else { return $input; } } function filter_html($input) { return strip_tags_attr($input, "