]> git.nbdom.net Git - nb.git/commitdiff
encoding strlen
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Sep 2016 11:09:35 +0000 (13:09 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Sep 2016 11:09:35 +0000 (13:09 +0200)
etc/dbs.yaml
lib/php/db.php
lib/php/db/types/mysql.php
lib/php/out.php

index c0e1c98bb1c7f0f0282e3b9506473ad6bb5c759e..77524aee50d654569e8dcb1fd2666e2449bba734 100644 (file)
@@ -24,6 +24,7 @@ izi:
   type: mysql
   _import:
     - _izi
+  encoding: utf-8
   tables:
     site:
       replace:
index 7ca9a620ff91136b89a29fd8486d39cc961d66fd..93c8eb66c45a8915382045beebf0d4524ec836d1 100644 (file)
@@ -58,8 +58,17 @@ class Db extends nb {
       unset($opt['tables']);
     }
 
+    # Encoding
+    if (isset($opt['encoding'])) {
+      self::$encoding = $opt['encoding'];
+      unset($opt['encoding']);
+    }
+
     # Args into this
     foreach ($opt as $k=>$v) $this->$k = $v;
+    #parent::__construct($opt);
+    #if(!is_scalar($opt['type'])) debug($opt['type']);
+    if (self::$encoding) out::$charset=self::$encoding;
 
     # id
     if (!empty($this->conf)) {
index aed29428611690aefdcc7f069a55320f4437acea..3e31be82b20e5af2edac68824a8b965a83c6ca48 100644 (file)
@@ -11,6 +11,7 @@ $DB_TYPES['mysql'] = array (
 'exec' => array_merge(
   [
     'SET NAMES '.str_replace('utf-8','utf8',strtolower(Db::$encoding)),
+    #'SET NAMES '.str_replace(['utf-8','utf8'],['utf8mb4','utf8mb4'],strtolower(Db::$encoding)),
   ],
   (Db::p('db.type') ? [
     "/*!40103 SET TIME_ZONE='+00:00' */",
index 2e1462007b92684a493c46461f9f19ef1bffc23a..2c9d8fa626f33441de5696ff8181daf33fe3280d 100644 (file)
@@ -170,11 +170,11 @@ Class Out extends Nb {
 
     } else if (self::is_hash($data[0])) {
 
-      $o['head_max_len'] = max(self::ar_map('strlen($a)',array_keys($data[0])));
+      $o['head_max_len'] = max(self::ar_map('mb_strlen($a)',array_keys($data[0])));
 
     } elseif (is_array($data[0])) {
       #debug($data);
-      $o['head_max_len'] = max(self::ar_map('strlen($a)',$data[0]));
+      $o['head_max_len'] = max(self::ar_map('mb_strlen($a)',$data[0]));
 
     }
 
@@ -223,7 +223,7 @@ Class Out extends Nb {
     }
 
 # NB 10.04.16     if (!self::is_hash($row)) unset($o['head_max_len']);
-# NB 10.04.16     if (is_array($row) and count($row)>1) $o['head_max_len'] = strlen(count($row));
+# NB 10.04.16     if (is_array($row) and count($row)>1) $o['head_max_len'] = mb_strlen(count($row));
     #if (!self::is_hash($row)) return out_yaml($row,$o);
 
     # text
@@ -231,7 +231,7 @@ Class Out extends Nb {
       echo sprintf("%"
         .(!empty($o['head_max_len']) ? '-'.($o['head_max_len']+1) : '')
         ."s: %s\n",$k,preg_replace('/\n(\w)/m'
-          ,"\n".str_repeat(' ',(empty($o['head_max_len']) ? strlen($k) : $o['head_max_len']+1)+2).'\1'
+          ,"\n".str_repeat(' ',(empty($o['head_max_len']) ? mb_strlen($k) : $o['head_max_len']+1)+2).'\1'
         ,self::format($v))
       );
     }
@@ -505,7 +505,12 @@ function out_human(&$row,&$o) {
   $line = out_csv($row,$o);
   $i = 0;
   foreach (explode($o['sep'],$line) as $v) {
-    $len = strlen($v);
+# NB 07.09.16     if (out::$charset == 'utf-8') {
+# NB 07.09.16       $len = strlen(utf8_decode($v));
+# NB 07.09.16     } else {
+# NB 07.09.16       $len = mb_strlen($v,out::$charset);
+# NB 07.09.16     }
+    $len = mb_strlen($v,out::$charset);
     if (0
       or empty($GLOBALS['_human_len'][$i])
       or $len > $GLOBALS['_human_len'][$i]