Req #19423 [Opn->Csd]: cell padding incorrect when use multi-byte chars
| From: | jan at horde dot org | Date: | Fri, 07 Dec 2012 14:48:07 +0000 |
| Subject: | Req #19423 [Opn->Csd]: cell padding incorrect when use multi-byte chars | ||
| References: | 1 | Groups: | php.pear.bugs |
| Request: | Send a blank email to pear-bugs+get-9399@lists.php.net to get a copy of this message | ||
Edit report at https://pear.php.net/bugs/bug.php?id=19423&edit=1
ID: 19423
Updated by: jan@horde.org
Reported By: liangzhenjing at gmail dot com
Summary: cell padding incorrect when use multi-byte chars
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Console_Table
Operating System: Mac OS X Lion 10.7.2
Package Version: 1.1.4
PHP Version: 5.3.6
-Assigned To:
+Assigned To: yunosh
Roadmap Versions:
New Comment:
-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/
Previous Comments:
------------------------------------------------------------------------
[2012-05-18 07:00:03] liang
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 |
+----------------+--------------------+
------------------------------------------------------------------------
--
Edit this bug report at https://pear.php.net/bugs/bug.php?id=19423&edit=1