@ 2014-10-04T00:42:48Z <?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) 8.3.6 0.006 0.011 18.31 8.3.5 0.010 0.013 21.93 8.3.4 0.015 0.000 18.84 8.3.3 0.004 0.011 19.17 8.3.2 0.004 0.004 20.61 8.3.1 0.008 0.000 20.53 8.3.0 0.008 0.000 19.31 8.2.18 0.011 0.007 16.88 8.2.17 0.009 0.009 22.96 8.2.16 0.011 0.003 20.72 8.2.15 0.003 0.006 24.18 8.2.14 0.005 0.003 24.66 8.2.13 0.009 0.000 26.16 8.2.12 0.004 0.004 22.23 8.2.11 0.000 0.011 21.18 8.2.10 0.004 0.008 17.97 8.2.9 0.006 0.003 19.25 8.2.8 0.000 0.008 17.97 8.2.7 0.007 0.003 17.75 8.2.6 0.003 0.006 18.17 8.2.5 0.010 0.000 18.10 8.2.4 0.000 0.008 18.34 8.2.3 0.004 0.004 19.45 8.2.2 0.004 0.004 17.68 8.2.1 0.000 0.008 18.08 8.2.0 0.004 0.004 17.82 8.1.28 0.007 0.007 25.92 8.1.27 0.004 0.004 22.35 8.1.26 0.005 0.003 26.35 8.1.25 0.006 0.003 28.09 8.1.24 0.003 0.009 22.45 8.1.23 0.000 0.013 19.05 8.1.22 0.000 0.008 17.91 8.1.21 0.010 0.000 18.77 8.1.20 0.011 0.000 17.48 8.1.19 0.000 0.008 17.23 8.1.18 0.004 0.004 18.10 8.1.17 0.006 0.003 18.75 8.1.16 0.000 0.008 22.18 8.1.15 0.008 0.000 18.98 8.1.14 0.000 0.008 17.49 8.1.13 0.000 0.008 18.00 8.1.12 0.006 0.003 17.57 8.1.11 0.000 0.008 17.43 8.1.10 0.003 0.006 17.54 8.1.9 0.000 0.007 17.53 8.1.8 0.005 0.003 17.41 8.1.7 0.005 0.002 17.57 8.1.6 0.003 0.005 17.57 8.1.5 0.003 0.006 17.65 8.1.4 0.003 0.006 17.51 8.1.3 0.000 0.009 17.75 8.1.2 0.004 0.004 17.79 8.1.1 0.004 0.004 17.63 8.1.0 0.005 0.003 17.52 8.0.30 0.006 0.003 18.77 8.0.29 0.004 0.004 16.75 8.0.28 0.004 0.004 18.58 8.0.27 0.000 0.007 17.25 8.0.26 0.003 0.003 17.39 8.0.25 0.004 0.003 17.13 8.0.24 0.008 0.000 17.00 8.0.23 0.008 0.000 17.07 8.0.22 0.004 0.004 17.07 8.0.21 0.002 0.005 17.05 8.0.20 0.004 0.004 16.98 8.0.19 0.004 0.004 17.01 8.0.18 0.004 0.004 17.04 8.0.17 0.004 0.004 17.04 8.0.16 0.008 0.000 16.96 8.0.15 0.003 0.006 16.89 8.0.14 0.003 0.005 17.00 8.0.13 0.000 0.006 13.48 8.0.12 0.003 0.006 17.04 8.0.11 0.004 0.004 17.02 8.0.10 0.005 0.002 16.90 8.0.9 0.003 0.006 17.01 8.0.8 0.004 0.011 17.10 8.0.7 0.004 0.005 17.06 8.0.6 0.008 0.000 16.85 8.0.5 0.004 0.004 16.94 8.0.3 0.004 0.015 17.11 8.0.2 0.015 0.009 17.40 8.0.1 0.004 0.004 16.96 8.0.0 0.009 0.009 16.94 7.4.33 0.000 0.007 15.00 7.4.32 0.007 0.000 16.62 7.4.30 0.004 0.004 16.69 7.4.29 0.006 0.003 16.68 7.4.28 0.006 0.006 16.72 7.4.27 0.003 0.004 16.73 7.4.26 0.004 0.004 16.50 7.4.25 0.004 0.004 16.56 7.4.24 0.004 0.004 16.57 7.4.23 0.000 0.007 16.54 7.4.22 0.014 0.014 16.79 7.4.21 0.009 0.006 16.57 7.4.20 0.004 0.004 16.69 7.4.16 0.010 0.007 16.59 7.4.15 0.007 0.011 17.40 7.4.14 0.009 0.011 17.86 7.4.13 0.007 0.012 16.59 7.4.12 0.011 0.008 16.66 7.4.11 0.009 0.009 16.72 7.4.10 0.015 0.006 16.59 7.4.9 0.012 0.006 16.65 7.4.8 0.003 0.014 16.72 7.4.7 0.013 0.010 16.80 7.4.6 0.006 0.012 16.62 7.4.5 0.003 0.006 16.75 7.4.4 0.012 0.006 16.84 7.4.3 0.010 0.007 16.57 7.4.0 0.008 0.004 14.77 7.3.33 0.003 0.003 13.42 7.3.32 0.005 0.003 13.27 7.3.31 0.004 0.004 16.29 7.3.30 0.000 0.007 16.39 7.3.29 0.003 0.010 16.38 7.3.28 0.005 0.011 16.40 7.3.27 0.003 0.021 17.40 7.3.26 0.011 0.006 16.52 7.3.25 0.009 0.009 16.40 7.3.24 0.018 0.000 16.36 7.3.23 0.012 0.006 16.39 7.3.21 0.008 0.011 16.63 7.3.20 0.016 0.006 19.39 7.3.19 0.014 0.007 16.39 7.3.18 0.007 0.010 16.47 7.3.17 0.005 0.014 16.56 7.3.16 0.012 0.004 16.69 7.3.1 0.000 0.012 16.70 7.3.0 0.000 0.010 16.28 7.2.33 0.006 0.012 16.67 7.2.32 0.011 0.007 16.72 7.2.31 0.012 0.006 16.71 7.2.30 0.000 0.018 16.74 7.2.29 0.014 0.006 16.53 7.2.13 0.004 0.012 16.64 7.2.12 0.006 0.009 16.79 7.2.11 0.007 0.007 16.61 7.2.10 0.007 0.007 16.63 7.2.9 0.003 0.007 16.46 7.2.8 0.006 0.009 16.53 7.2.7 0.003 0.012 16.81 7.2.6 0.010 0.007 16.79 7.2.5 0.003 0.007 16.86 7.2.4 0.007 0.007 16.75 7.2.3 0.006 0.010 16.67 7.2.2 0.011 0.007 16.57 7.2.1 0.008 0.008 16.43 7.2.0 0.002 0.011 17.73 7.1.25 0.009 0.000 15.77 7.1.20 0.004 0.008 15.57 7.1.10 0.008 0.008 17.84 7.1.7 0.000 0.007 16.68 7.1.6 0.007 0.018 19.32 7.1.5 0.006 0.019 16.90 7.1.0 0.010 0.070 22.40 7.0.20 0.007 0.003 16.73 7.0.14 0.000 0.077 21.94 7.0.10 0.007 0.097 20.18 7.0.9 0.013 0.067 20.21 7.0.8 0.007 0.083 20.34 7.0.7 0.003 0.080 20.13 7.0.6 0.007 0.063 20.09 7.0.5 0.047 0.053 20.50 7.0.4 0.013 0.073 20.11 7.0.3 0.003 0.083 20.11 7.0.2 0.003 0.083 20.18 7.0.1 0.010 0.073 19.91 7.0.0 0.017 0.043 20.14 5.6.28 0.000 0.073 21.21 5.6.25 0.003 0.087 20.76 5.6.24 0.007 0.087 20.63 5.6.23 0.017 0.070 20.72 5.6.22 0.020 0.070 20.76 5.6.21 0.023 0.067 20.70 5.6.20 0.003 0.050 21.18 5.6.19 0.003 0.090 21.30 5.6.18 0.017 0.077 21.23 5.6.17 0.003 0.093 21.18 5.6.16 0.003 0.043 21.18 5.6.15 0.010 0.080 21.19 5.6.14 0.010 0.047 21.23 5.6.13 0.010 0.077 21.14 5.6.12 0.010 0.080 21.23 5.6.11 0.007 0.050 21.20 5.6.10 0.010 0.077 21.13 5.6.9 0.007 0.080 21.04 5.6.8 0.007 0.080 20.51 5.6.7 0.003 0.080 20.64 5.6.6 0.010 0.050 20.66 5.6.5 0.003 0.060 20.54 5.6.4 0.010 0.077 20.52 5.6.3 0.010 0.053 20.42 5.6.2 0.003 0.040 20.41 5.6.1 0.007 0.037 20.61 5.6.0 0.003 0.047 20.57 5.5.38 0.007 0.080 20.71 5.5.37 0.010 0.080 20.70 5.5.36 0.007 0.053 20.47 5.5.35 0.007 0.080 20.55 5.5.34 0.003 0.073 20.97 5.5.33 0.007 0.067 20.93 5.5.32 0.013 0.077 21.06 5.5.31 0.003 0.087 20.75 5.5.30 0.007 0.087 21.02 5.5.29 0.007 0.080 21.02 5.5.28 0.010 0.083 20.93 5.5.27 0.010 0.077 20.89 5.5.26 0.010 0.077 21.04 5.5.25 0.007 0.090 20.80 5.5.24 0.013 0.040 20.39 5.5.23 0.007 0.087 20.43 5.5.22 0.000 0.077 20.30 5.5.21 0.007 0.047 20.41 5.5.20 0.010 0.080 20.34 5.5.19 0.013 0.033 20.39 5.5.18 0.000 0.067 20.36 5.5.16 0.007 0.047 20.21 5.5.15 0.007 0.037 20.23 5.5.14 0.000 0.043 20.28 5.5.13 0.007 0.037 20.35 5.5.12 0.007 0.033 20.21 5.5.11 0.007 0.037 20.19 5.5.10 0.013 0.027 20.27 5.5.9 0.010 0.070 20.22 5.5.8 0.003 0.043 20.16 5.5.7 0.003 0.040 20.22 5.5.6 0.000 0.040 20.23 5.5.5 0.000 0.040 20.23 5.5.4 0.003 0.057 20.07 5.5.3 0.003 0.037 20.26 5.5.2 0.007 0.060 20.17 5.5.1 0.007 0.063 20.15 5.5.0 0.007 0.043 20.15 5.4.45 0.000 0.087 19.60 5.4.44 0.010 0.077 19.27 5.4.43 0.003 0.060 19.56 5.4.42 0.007 0.073 19.42 5.4.41 0.010 0.083 19.27 5.4.40 0.013 0.073 19.17 5.4.39 0.010 0.077 19.14 5.4.38 0.003 0.047 19.09 5.4.37 0.007 0.050 18.94 5.4.36 0.000 0.043 19.11 5.4.35 0.007 0.047 19.10 5.4.34 0.010 0.053 19.18 5.4.32 0.003 0.043 19.11 5.4.31 0.000 0.040 19.14 5.4.30 0.007 0.040 19.23 5.4.29 0.003 0.037 19.16 5.4.28 0.000 0.040 19.09 5.4.27 0.007 0.033 19.23 5.4.26 0.003 0.040 19.24 5.4.25 0.000 0.040 19.08 5.4.24 0.003 0.070 19.19 5.4.23 0.007 0.033 19.14 5.4.22 0.010 0.053 19.23 5.4.21 0.003 0.037 19.09 5.4.20 0.000 0.043 19.16 5.4.19 0.000 0.080 19.23 5.4.18 0.003 0.037 19.23 5.4.17 0.003 0.037 19.00 5.4.16 0.007 0.030 18.99 5.4.15 0.003 0.043 19.07 5.4.14 0.010 0.027 16.51 5.4.13 0.003 0.033 16.44 5.4.12 0.000 0.037 16.59 5.4.11 0.010 0.027 16.54 5.4.10 0.003 0.047 16.43 5.4.9 0.003 0.033 16.45 5.4.8 0.003 0.073 16.47 5.4.7 0.003 0.037 16.49 5.4.6 0.010 0.037 16.41 5.4.5 0.003 0.033 16.40 5.4.4 0.003 0.037 16.41 5.4.3 0.003 0.037 16.52 5.4.2 0.000 0.037 16.42 5.4.1 0.000 0.060 16.50 5.4.0 0.007 0.050 16.00
preferences:dark mode live preview
51.9 ms | 401 KiB | 5 Q