From 439ea10e97fc17837396bc4e48747a2ec9a387cf Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sun, 4 Sep 2016 01:49:08 +0100 Subject: [PATCH] Bed --- lib/php/out.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/php/out.php b/lib/php/out.php index 66884920..54cab196 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -15,6 +15,7 @@ Class Out extends Nb { 'border' => '_', 'head' => 'out_human_head', 'function' => 'out_human', + 'end' => function($o) { echo $o['line']."\n"; } ], 'sql' => array(), @@ -250,8 +251,9 @@ Class Out extends Nb { if (isset($o['eol'])) echo $o['eol']; } - public static function end($o) { + public static function end(&$o) { if (isset($o['enclose'])) echo $o['enclose'][1]; + if (isset($o['end'])) echo $o['end']($o); } public static function rows_get($type,$data,$head=array()) { @@ -409,16 +411,16 @@ function out_human_head(&$head,&$o) { # For no scalar search max length $o['fields_max_len'] = []; - foreach ($o['data'] as $rec) { - $i = 0; + foreach ($o['data'] as $id=>$rec) { + $i = -1; foreach ($rec as $k=>$v) { + $i++; if (!is_scalar($v)) continue; if (0 or empty($o['fields_max_len'][$i]) or strlen($v) >= $o['fields_max_len'][$i] - ) $o['fields_max_len'][$i] = strlen($v); + ) $o['fields_max_len'][$i] = mb_strlen($v); #echo strlen($v)."\n"; - $i++; } } @@ -426,15 +428,15 @@ function out_human_head(&$head,&$o) { $head = array_keys($head); } - $i = 0; + $i = -1; foreach ($head as $k => $v) { + $i++; if (!is_scalar($v)) continue; if (0 or empty($o['fields_max_len'][$i]) or strlen($v) >= $o['fields_max_len'][$i] - ) $o['fields_max_len'][$i] = strlen($v); + ) $o['fields_max_len'][$i] = mb_strlen($v); #echo strlen($v)."\n"; - $i++; } #debug($line); @@ -460,7 +462,7 @@ function out_human(&$row,$o) { $i = 0; $values = []; foreach (array_values($row) as $k=>$v) { - #debug(strlen($v).' == '.$o['fields_max_len'][$i]); + #if(mb_strlen($v)!=$o['fields_max_len'][$i]) debug(mb_strlen($v).' == '.$o['fields_max_len'][$i]); #debug("%".$o['fields_max_len'][$i]."s"); $values[] = sprintf("%".'-'.$o['fields_max_len'][$i] -- 2.47.3