array(), 'commands' => array(), 'flags' => array() ); foreach ( $args as $arg ) { // Is it a command? (prefixed with --) if ( substr( $arg, 0, 2 ) === '--' ) { $value = preg_split( '/[= ]/', $arg, 2 ); $com = substr( array_shift($value), 2 ); $value = join($value); $ret['commands'][$com] = !empty($value) ? $value : true; continue; } // Is it a flag? (prefixed with -) if ( substr( $arg, 0, 1 ) === '-' ) { $ret['flags'][] = substr( $arg, 1 ); continue; } $ret['input'][] = $arg; continue; } return $ret; } function console($message, $EOL = true, $log = true, $level = 1){ //global $path; if(!defined("DEBUG") or DEBUG >= $level){ $message .= $EOL === true ? PHP_EOL:""; $message = date("H:i:s"). " ". $message; if($log === true and (!defined("LOG") or LOG === true)){ logg($message, "console", false, $level); } echo $message; } } function logg($message, $name, $EOL = true, $level = 2, $close = false){ global $fpointers; if((!defined("DEBUG") or DEBUG >= $level) and (!defined("LOG") or LOG === true)){ $message .= $EOL === true ? PHP_EOL:""; if(!isset($fpointers)){ $fpointers = array(); } if(!isset($fpointers[$name])){ $fpointers[$name] = fopen(FILE_PATH."/".$name.".log", "ab"); } fwrite($fpointers[$name], $message); if($close === true){ fclose($fpointers[$name]); unset($fpointers[$name]); } } } function hexdump($data, $htmloutput = true, $uppercase = false, $return = false) { // Init $hexi = ''; $ascii = ''; $dump = ($htmloutput === true) ? '
' : '';
$offset = 0;
$len = strlen($data);
// Upper or lower case hexadecimal
$x = ($uppercase === false) ? 'x' : 'X';
// Iterate string
for ($i = $j = 0; $i < $len; $i++)
{
// Convert to hexidecimal
$hexi .= Utils::strToHex($data[$i]);
// Replace non-viewable bytes with '.'
if (ord($data[$i]) >= 0x20 and ord($data[$i]) < 0x80) {
$ascii .= ($htmloutput === true) ?
htmlentities($data[$i]) :
$data[$i];
} else {
$ascii .= '.';
}
// Add extra column spacing
if ($j === 7) {
$hexi .= ' ';
$ascii .= ' ';
}
// Add row
if (++$j === 16 || $i === $len - 1) {
// Join the hexi / ascii output
$dump .= sprintf("%04$x %-49s %s", $offset, $hexi, $ascii);
// Reset vars
$hexi = $ascii = '';
$offset += 16;
$j = 0;
// Add newline
if ($i !== $len - 1) {
$dump .= "\n";
}
}
}
// Finish dump
$dump .= $htmloutput === true ?
'' :
'';
$dump .= "\n";
$dump = preg_replace("/[^[:print:]\\r\\n]/", ".", $dump);
// Output method
if ($return === false) {
echo $dump;
} else {
return $dump;
}
}