PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Console » Console_Table » Bug #7014

Multi-byte strlen() improvement

Details

Request #7014Multi-byte strlen() improvement
Submitted2006-03-04 12:35 UTC
Fromkoto at webworkers dot pl
Assignedyunosh
StatusClosed
PackageConsole_Table
PHP VersionIrrelevant
OSwin
Roadmaps(Not assigned)

Comments

[2006-03-04 12:35 UTC] koto at webworkers dot pl

Description:
------------
Current stable release 1.0.2 does not support multi-byte characters which results in invalid column-length calculations for UTF-8 strings.

As I can see, the CVS version already addresses this issue by providing setCharset() function and using mb_string() function. This hovewer limits possible usage to PHP users that have multibyte extension compiled in, which is not so common in shared config environments.

The solution for those not having multibyte extension would be to use the following snippet:
( found @ http://pl.php.net/manual/en/function.strlen.php#45407 )

$length = strlen(utf8_decode($s));

utf8_decode() converts characters that are not in ISO-8859-1 to '?', which, for the purpose of counting, is quite alright.

I propose adding the function as a fallback method to the _strlen() function in CVS version, so instead of:

return strlen($str);

we do:

return strlen(utf8_decode($str));