note 110336 deleted from function.mb-strlen by googleguy
| From: | googleguy@php.net | Date: | Fri, 12 Oct 2012 10:58:56 +0000 |
| Subject: | note 110336 deleted from function.mb-strlen by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191269@lists.php.net to get a copy of this message | ||
Note Submitter: qeremy [atta] gmail [dotta] com
----
A dirty (proper) way to get the real length of charters (not byte length).
<?php
function strlen_unicode($str) {
return count(preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY));
}
$s = "Büyük";
echo strlen_unicode($s); // 5
echo mb_strlen($s); // 7
echo strlen($s); // 7
?>