@ 2014-10-04T00:40:02Z <?php
class __Utils
{
public static function setHeader(string $header, $variable, $replace = false, $httpresponse = null)
{
if($httpresponse !== null) {
header("$header: $variable", $replace, $httpresponse);
} else {
header("$header: $variable", $replace);
}
}
public static function setHeaders(array $headers)
{
foreach($headers as $header => $variables){
if(is_array($variables)) {
$replace = (isset($variables[1]) && self:isBoolean($variables[1])) ? $variables[1] : true;
if( isset($variables[2]) && self::isInteger($variables[2]) ) {
self::setHeader($header, $variables[0], $replace, $variables[2]);
} else {
self::setHeader($header, $variables[0], $replace);
}
} else {
self:setHeader($header, $variables);
}
}
}
public static function spaces($count, $htmlentities = true)
{
$spaces = str_repeat(' ', (int) $count);
return ($htmlentities) ? $spaces : str_replace(' ', '', $spaces);
}
public static function tabs($count, $tabsize = 6)
{
return self::spaces(((int) $tabsize * (int) $count));
}
public static function lineBreaks($count, $heightpx = 16) {
return str_repeat('<br style="height: ' . $heightpx . 'px;" />', (int) $count);
}
public static function isArray($variable)
{
return (is_array($variable));
}
public static function isBoolean($variable)
{
return (is_bool($variable));
}
public static function isString($variable)
{
return (is_string($variable));
}
public static function isNull($variable)
{
return (is_null($variable));
}
public static function isCallable($variable)
{
return (is_callable($variable));
}
public static function isObject($variable)
{
return (is_object($variable));
}
public static function isDouble($variable)
{
return (is_double($variable));
}
public static function isFloat($variable)
{
return (is_float($variable));
}
public static function isInteger($variable)
{
return (is_int($variable));
}
public static function isLong($variable)
{
return (is_long($variable));
}
public static function isResource($variable)
{
return (is_resource($variable));
}
public static function getVarType($variable)
{
$typecases = array(
"array" => self::isArray($variable),
"boolean" => self::isBoolean($variable),
"string" => self::isString($variable),
"null" => self::isNull($variable),
"callable" => self::isCallable($variable),
"object" => self::isObject($variable),
"double" => self::isDouble($variable),
"integer" => self::isInteger($variable),
"float" => self::isFloat($variable),
"long" => self::isLong($variable),
"resource" => self::isResource($variable)
);
foreach($typecases as $type => $bool){
if($bool) return $type;
}
}
public static function nocacheHaders()
{
if (!headers_sent()) {
self::setHeaders(array(
"Expires" => "Wed, 11 Jan 1984 05:00:00 GMT",
"Last-Modified" => gmdate( 'D, d M Y H:i:s' ) . " GMT",
"Cache-Control" => "no-cache, must-revalidate, max-age=0",
"Pragma" => "no-cache",
));
}
}
public static function stripSpace(string $string)
{
return str_replace(' ', '', preg_replace('/\s+/', '', $string));
}
public static function sanitize(string $string)
{
$sanitized = $string;
$sanitized = strip_tags($sanitized);
$sanitized = htmlspecialchars($sanitized, ENT_QUOTES, 'utf-8');
$sanitized = htmlentities($sanitized, ENT_HTML5, 'utf-8');
return $sanitized;
}
public static function dumpVar($variable, $doreturn = false, $dopre = true, $styles = true, $tabamt = 1)
{
$return = '';
$wrapper = ($dopre === null) ? 'none' : ((self::isBoolean($dopre)) ? (($dopre) ? 'pre' : 'div' ) : $dopre );
$class = ($styles) ? 'styled' : 'nostyles';
$settings = array(
'wrappers' => array(
'none' => '%s',
'pre' => '<pre class="vardump ' . $class . '">%s</pre>',
'div' => '<div class="vardump ' . $class . '">%s</div>'
),
'sprintf' => array(
'vartype' => '<span class="vartype">%s</span>',
'specialvartype' => '<span class="specialvartype">%s</span>',
'parentheses' => '<span class="parentheses">(</span><span class="parcont">%s</span><span class="parentheses">)</span>',
'string' => '<span class="misc">"%s"</span>',
'raw' => '<span class="misc">%s</span>',
'arrkey' => '<span class="misc">' . self::tabs($tabamt) . '[%s]</span>',
'arrsep' => '<span class="arrsep">=></span>'
),
);
switch(self::getVarType($variable)) {
case "boolean":
$return .= sprintf($settings['sprintf']['vartype'], 'bool') . sprintf($settings['sprintf']['parentheses'], (string) $variable ? 'true' : 'false');
break;
case "integer":
$return .= sprintf($settings['sprintf']['vartype'], 'int') . sprintf($settings['sprintf']['parentheses'], (string) $variable);
break;
case "double":
$return .= sprintf($settings['sprintf']['vartype'], 'double') . sprintf($settings['sprintf']['parentheses'], (string) $variable);
break;
case "float":
$return .= sprintf($settings['sprintf']['vartype'], 'float') . sprintf($settings['sprintf']['parentheses'], (string) $variable);
break;
case "string":
$return .= sprintf($settings['sprintf']['vartype'], 'string') . sprintf($settings['sprintf']['parentheses'], (string) strlen($variable)) . " " . sprintf($settings['sprintf']['string'], $variable);
break;
case "null":
$return .= sprintf($settings['sprintf']['specialvartype'], 'NULL');
break;
case "array":
$brackets = array('{');
foreach($variable as $key => $value) {
$brackets[] = sprintf($settings['sprintf']['arrkey'], $key) . " " . $settings['sprintf']['arrsep'] . " " . self::dumpVar($value, true, null, $styles, $tabamt + 1) . ',';
}
$brackets[] = ($tabamt < 2) ? '}' : self::tabs(($tabamt - 1)) . '}';
$brackets = ($dopre) ? implode("\n", $brackets) : implode('<br />', $brackets);
$return .= sprintf($settings['sprintf']['vartype'], 'array') . sprintf($settings['sprintf']['parentheses'], (string) count($variable)) . " " . $brackets;
break;
case "object":
$reflclass = new ReflectionClass($variable);
$constants = $reflclass->getConstants();
$variables = $reflclass->getProperties();
$methods = $reflclass->getMethods();
$brackets = array('{');
foreach($constants as $name => $value) {
$brackets[] = self::tabs($tabamt) . sprintf($settings['sprintf']['raw'], 'CONST ' . $name) . ' ' . self::dumpVar($value, true, null, $styles);
}
foreach($variables as $var) {
}
$return .= sprintf($settings['sprintf']['vartype'], 'object') . sprintf($settings['sprintf']['parentheses'], get_class($variable));
break;
default:
$return .= sprintf($settings['sprintf']['specialvartype'], 'UNKNOWN TYPE') . ' ' . sprintf($settings['sprintf']['raw'], var_export($variable, true));
break;
}
if($dopre) $return = str_ireplace(' ', ' ', $return);
$returnwrapper = (array_key_exists($wrapper, $settings['wrappers'])) ? $settings['wrappers'][$wrapper] : $settings['wrappers']['none'];
$return = sprintf($returnwrapper, $return);
if($doreturn) return $return;
echo $return;
}
public static function dumpVars($variables, $doreturn = false, $dopre = true, $styles = true, $tabamt = 1)
{
$return = array();
foreach($variables as $var) {
$return[] = self::dumpVar($var, true, $dopre, $styles, $tabamt);
}
$return = implode(self::lineBreaks(1), $return);
if($doreturn) return $return;
echo $return;
}
public static function outputData(string $filename, string $content = null, $mimetype = "auto")
{
$mimetype =
(is_file($filename)) ?
finfo_file(finfo_open(FILEINFO_MIME, pathinfo($content, PATHINFO_DIRNAME), $content)) :
($mimetype == "auto") ? "application/force-download" :
$mimetype;
if(!headers_sent()) {
$output = is_null($content) ? file_get_contents($file) : $content;
self:setHeaders(array(
"Pragma" => "public",
"Expires" => "0",
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
"Cache-Control" => array("private", FALSE),
"Content-Disposition" => "attatchment; filename=" . basename(str_replace('"', '', $filename)) . '";',
"Content-Type" => $mimetype,
"Content-Transer-Encoding" => "binary",
"Content-Length" => strlen($output),
));
ob_clean();
flush();
echo $output;
exit();
}
}
public static function forceDownload($file, $content = null)
{
self::outputData($file, $content, "application/force-download");
}
public static function uniqueId($prefix = null, $format = '{35}') // Ex: {8}-{4}-{4}-{4}-{12} will return something like XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
{
$uniqueid = $prefix;
$alpha = range('a', 'z', 1);
$alphacase = range('A', 'Z', 1);
$num = range('1', '999', 1);
$rand1 = array_rand($alpha, 5);
$rand2 = array_rand($alphacase, 5);
$rand3 = array_rand($num, 5);
$rand = array_merge($rand1, $rand2, $rand3);
$datetime = new DateTime('now', new DateTimeZone('America/New_York'));
$timestamp = $datetime->format('c');
$uniqueid .= implode('', $rand) . "_" . $timestamp . "_" . uniqid();
$origuniqueid = $uniqueid;
foreach(hash_algos() as $algo) {
$uniqueid = hash($algo, $uniqueid . "_" . $timestamp . "_" . uniqid());
}
$uniqueid = md5($uniqueid);
$chararrays = array();
$finaluniqueid = '';
$amount = 10;
for($time = $amount; $time > 0; $time--) {
$chararrays[$time] = str_split($uniqueid);
shuffle($chararrays[$time]);
$finaluniqueid .= implode('', array_slice($chararrays[$time], rand(0, (count($chararrays[$time]) - 1)), rand(0, (count($chararrays[$time]) - 1))));
}
$finaluniqueid = str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid) . str_shuffle($finaluniqueid);
$formateduniqueid = $format;
$substart = 0;
preg_match_all('([0-9]+)', $format, $ints);
foreach($ints[0] as $int) {
if($newi > strlen($formateduniqueid) ) $newi = strlen($formateduniqueid);
$substr = substr($finaluniqueid, $substart, ((int) $int));
$formateduniqueid = preg_replace('/\{' . $int . '\}/', $substr, $formateduniqueid, 1);
$substart = $substart + ((int) $int);
}
return $formateduniqueid;
}
public static function getRelativePath($from, $to)
{
$from = is_dir($from) ? rtrim($from, '\/') . '/' : $from;
$to = is_dir($to) ? rtrim($to, '\/') . '/' : $to;
$from = str_replace('\\', '/', $from);
$to = str_replace('\\', '/', $to);
$from = explode('/', $from);
$to = explode('/', $to);
$relPath = $to;
foreach($from as $depth => $dir) {
if($dir === $to[$depth]) {
array_shift($relPath);
} else {
$remaining = count($from) - $depth;
if($remaining > 1) {
$padLength = (count($relPath) + $remaining - 1) * -1;
$relPath = array_pad($relPath, $padLength, '..');
break;
} else {
$relPath[0] = './' . $relPath[0];
}
}
}
return implode('/', $relPath);
}
public static function arrayList(array $array, $withkeys = false, $keysep = ': ') {
if($withkeys) {
foreach($array as $k => $v) {
$array[$k] = $k . $keysep . $v;
}
}
switch(count($array)) {
case 1:
return implode('', $array);
break;
case 2:
return implode(' and ', $array);
break;
case 3:
$arrv = array_values($array);
$array[array_search($arrv[(count($arrv) - 1)], $array)] = 'and ' . $array[array_search($arrv[(count($arrv) - 1)], $array)];
$output = implode(', ', $array);
if(strtoupper(Locale::getRegion(Locale::getDefault())) === 'GB') $output = str_replace(', and', ' and ', $output);
return $output;
}
}
public static function pluckArrays($key, $value, $arrays) {
$return = array();
foreach($arrays as $array) {
if($array[$key] === $value) {
$return[] = $array;
}
}
return $return;
}
public static function addQuotes($string, $quote = '"') {
return $quote . $string . $quote;
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.32 0.006 0.037 12.52 5.4.31 0.008 0.037 12.52 5.4.30 0.007 0.036 12.52 5.4.29 0.006 0.039 12.52 5.4.28 0.006 0.036 12.41 5.4.27 0.011 0.034 12.41 5.4.26 0.003 0.041 12.41 5.4.25 0.008 0.036 12.41 5.4.24 0.004 0.037 12.41 5.4.23 0.005 0.039 12.41 5.4.22 0.007 0.035 12.41 5.4.21 0.005 0.037 12.41 5.4.20 0.009 0.040 12.40 5.4.19 0.008 0.034 12.40 5.4.18 0.003 0.039 12.40 5.4.17 0.008 0.034 12.41 5.4.16 0.009 0.033 12.41 5.4.15 0.004 0.038 12.40 5.4.14 0.008 0.035 12.09 5.4.13 0.007 0.034 12.07 5.4.12 0.002 0.039 12.04 5.4.11 0.006 0.035 12.04 5.4.10 0.005 0.036 12.03 5.4.9 0.007 0.036 12.03 5.4.8 0.008 0.035 12.04 5.4.7 0.005 0.036 12.04 5.4.6 0.002 0.039 12.03 5.4.5 0.009 0.032 12.03 5.4.4 0.005 0.035 12.02 5.4.3 0.005 0.036 12.02 5.4.2 0.006 0.035 12.02 5.4.1 0.006 0.035 12.02 5.4.0 0.006 0.037 11.51 5.3.29 0.007 0.038 12.80 5.3.28 0.005 0.054 12.71 5.3.27 0.004 0.042 12.72 5.3.26 0.009 0.037 12.72 5.3.25 0.009 0.033 12.72 5.3.24 0.004 0.038 12.72 5.3.23 0.007 0.036 12.71 5.3.22 0.003 0.040 12.68 5.3.21 0.004 0.041 12.68 5.3.20 0.008 0.035 12.68 5.3.19 0.003 0.041 12.68 5.3.18 0.005 0.037 12.68 5.3.17 0.010 0.032 12.67 5.3.16 0.007 0.035 12.67 5.3.15 0.007 0.036 12.67 5.3.14 0.005 0.037 12.66 5.3.13 0.004 0.040 12.66 5.3.12 0.006 0.038 12.66 5.3.11 0.005 0.039 12.66 5.3.10 0.006 0.036 12.13 5.3.9 0.005 0.036 12.11 5.3.8 0.009 0.032 12.09 5.3.7 0.007 0.035 12.09 5.3.6 0.002 0.041 12.09 5.3.5 0.008 0.035 12.03 5.3.4 0.006 0.037 12.03 5.3.3 0.004 0.042 11.99 5.3.2 0.007 0.047 11.77 5.3.1 0.003 0.039 11.74 5.3.0 0.005 0.037 11.72 5.2.17 0.005 0.030 9.23 5.2.16 0.004 0.030 9.23 5.2.15 0.005 0.030 9.23 5.2.14 0.006 0.028 9.23 5.2.13 0.006 0.027 9.19 5.2.12 0.002 0.031 9.19 5.2.11 0.003 0.030 9.20 5.2.10 0.006 0.027 9.20 5.2.9 0.006 0.027 9.20 5.2.8 0.005 0.031 9.19 5.2.7 0.009 0.033 9.19 5.2.6 0.006 0.034 9.14 5.2.5 0.003 0.031 9.11 5.2.4 0.004 0.029 9.08 5.2.3 0.003 0.031 9.07 5.2.2 0.007 0.026 9.05 5.2.1 0.008 0.032 8.96 5.2.0 0.003 0.033 8.83 5.1.6 0.007 0.024 8.10 5.1.5 0.006 0.026 8.10 5.1.4 0.003 0.029 8.08 5.1.3 0.003 0.027 8.43 5.1.2 0.005 0.026 8.45 5.1.1 0.004 0.025 8.18 5.1.0 0.002 0.027 8.18 5.0.5 0.003 0.021 6.66 5.0.4 0.003 0.019 6.51 5.0.3 0.004 0.030 6.33 5.0.2 0.002 0.020 6.30 5.0.1 0.003 0.020 6.27 5.0.0 0.003 0.031 6.26 4.4.9 0.001 0.017 4.78 4.4.8 0.003 0.015 4.75 4.4.7 0.003 0.015 4.76 4.4.6 0.003 0.015 4.75 4.4.5 0.001 0.017 4.77 4.4.4 0.004 0.023 4.71 4.4.3 0.002 0.016 4.76 4.4.2 0.002 0.016 4.84 4.4.1 0.002 0.016 4.85 4.4.0 0.003 0.024 4.76 4.3.11 0.003 0.019 4.67 4.3.10 0.005 0.013 4.66 4.3.9 0.002 0.016 4.64 4.3.8 0.002 0.025 4.58 4.3.7 0.005 0.013 4.63 4.3.6 0.001 0.016 4.63 4.3.5 0.004 0.015 4.63 4.3.4 0.004 0.031 4.53 4.3.3 0.003 0.020 3.31 4.3.2 0.003 0.020 3.29 4.3.1 0.002 0.021 3.24 4.3.0 0.010 0.017 6.73
preferences:dark mode live preview
144.86 ms | 939 KiB | 8 Q