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

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 (version 1.0.2)
PHP Version: Irrelevant OS: win
Roadmaps: (Not assigned)    
Subscription  


 [2006-03-04 12:35 UTC] koto at webworkers dot pl (koto)
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));

Comments

 [2006-03-04 16:14 UTC] yunosh
That's an interesting solution. Of course it only works if using the UTF-8 charset, but for this case it's a nice fallback.
 [2006-03-12 23:34 UTC] yunosh
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.