$v ) { $varsArray['{'.$k.'}'] = $v; } $data = str_replace(array_keys($varsArray), array_values($varsArray), $data); } echo $data; } /** * Write Line * * @param mixed $data = NULL * @param array $vars = NULL * @param int $brCount = 1 * * @return void */ public static function writeLine($data = NULL, ?array $vars = NULL, int $brCount = 1) { echo self::write($data, $vars) . str_repeat('
', $brCount); } /** * Display * * @param mixed $data = NULL * @param array $vars = NULL * @param bool $content = false * * @return void */ public static function display($data, ?array $settings = NULL, bool $content = false) { $textType = $settings['textType'] ?? 'monospace, Tahoma, Arial'; $textSize = $settings['textSize'] ?? '12px'; $globalStyle = ' style="font-family:'.$textType.'; font-size:'.$textSize .';"'; $output = ""; $output .= self::_output($data, '', 0, (array) $settings); $output .= ""; if( $content === false) { echo $output; } else { return $output; } } /** * Protected Output * * @param mixed $data * @param string $tab = NULL * @param int $start = 0 * @param array $settings = [] * * @return void */ protected static function _output($data, ?string $tab = NULL, int $start = 0, array $settings = []) : string { static $start; $lengthColor = $settings['lengthColor'] ?? 'grey'; $keyColor = $settings['keyColor'] ?? '#000'; $typeColor = $settings['typeColor'] ?? '#8C2300'; $stringColor = $settings['stringColor'] ?? 'red'; $numericColor = $settings['numericColor'] ?? 'green'; $output = ''; $eof = '
'; $tab = str_repeat('        ', (int) $start); $lengthstyle = ' style="color:'.$lengthColor.'"'; $keystyle = ' style="color:'.$keyColor.'"'; $typestyle = ' style="color:'.$typeColor.'"'; $vartype = 'array'; if( is_object($data) ) { $data = (array) $data; $vartype = 'object'; } if( ! is_array($data) ) { return $data.$eof; } else { foreach( $data as $k => $v ) { if( is_object($v) ) { $v = (array) $v; $vartype = 'object'; } if( ! is_array($v) ) { $valstyle = ' style="color:'.$numericColor.';"'; $type = gettype($v); if( $type === 'string' ) { $v = "'".$v."'"; $valstyle = ' style="color:'.$stringColor.';"'; $type = 'string'; } elseif( $type === 'boolean' ) { $v = ( $v === true ) ? 'true' : 'false'; $type = 'boolean'; } $output .= "$tab$k => $type $v ( length = ".strlen((string) $v)." )$eof"; } else { $output .= "$tab$k => $vartype $eof $tab( $eof ".self::_output($v, $tab, (int) $start++)." $tab) ".$eof; $start--; } } } return $output; } }