Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.1

Request #19423 cell padding incorrect when use multi-byte chars
Submitted: 2012-05-18 11:00 UTC
From: liang Assigned: yunosh
Status: Closed Package: Console_Table (version 1.1.4)
PHP Version: 5.3.6 OS: Mac OS X Lion 10.7.2
Roadmaps: (Not assigned)    
Subscription  


 [2012-05-18 11:00 UTC] liang (Liang Zhenjing)
Description: ------------ I'm from China, so i use Chinese as example below. for a utf8-encoded Chinese char '?': 3 == strlen('?') 1 == mb_strlen('?', 'utf8') 2 == mb_strwidth('?', 'utf8') but when output to a terminal, a Chinese char takes 2 monospaces, that causes Console_Table padding incorrectly. one solution is use mb_strwidth to calc text width instead, that works for me. for some unknown reason, i can't upload patch file(may be there is a bug in this bug tracker? i'm using chrome 18), so i put my patch here: ---------------------------------------------------- 780c780 < static $mbstring, $utf8, $mbstrwidth; --- > static $mbstring, $utf8; 794,801d793 < if (!isset($mbstrwidth)) { < $mbstrwidth= function_exists('mb_strwidth'); < } < < if($mbstrwidth) < { < return mb_strwidth($str, $this->_charset); < } Test script: --------------- <?php include 'Console/Table.php'; $table = new Console_Table(); $table->setHeaders(array('Message', 'Email')); $table->addRow(array("I'm from ??", 'dummy1@example.com')); $table->addRow(array("?????", 'dummy2@example.com')); $table->addRow(array("I'm from China", 'dummy3@example.com')); echo $table->getTable(); Expected result: ---------------- +----------------+--------------------+ | Message | Email | +----------------+--------------------+ | I'm from ?? | dummy1@example.com | | ????? | dummy2@example.com | | I'm from China | dummy2@example.com | +----------------+--------------------+ Actual result: -------------- +----------------+--------------------+ | Message | Email | +----------------+--------------------+ | I'm from ?? | dummy1@example.com | | ????? | dummy2@example.com | | I'm from China | dummy3@example.com | +----------------+--------------------+

Comments

 [2012-12-07 19:48 UTC] yunosh (Jan Schneider)
-Status: Open +Status: Closed -Assigned To: +Assigned To: yunosh
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/