note 96931 deleted from function.strlen by danbrown

From: Date: Tue, 23 Mar 2010 20:22:30 +0000
Subject: note 96931 deleted from function.strlen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167328@lists.php.net to get a copy of this message
Note Submitter: admin at smitelli dot com ---- in reply to 'jonathan dot protzenko at gmail dot com': Your function for counting Unicode characters in a string is spot-on, but it's a little inefficient. You can do the same thing in one line: <?php function unicode_strlen($str) { return count(preg_split('//u', $str)) - 2; } ?> It's a little ugly (with the magic constant and all) but it's a lot cleaner without that foreach loop.

« previous php.notes (#167328) next »