Home » Console » Console_Table » Bug #7014
Multi-byte strlen() improvement
Details
| Request #7014 | Multi-byte strlen() improvement |
|---|---|
| Submitted | 2006-03-04 12:35 UTC |
| From | koto at webworkers dot pl |
| Assigned | yunosh |
| Status | Closed |
| Package | Console_Table |
| PHP Version | Irrelevant |
| OS | win |
| 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));