note 96931 added to function.strlen

From: Date: Tue, 23 Mar 2010 20:21:36 +0000
Subject: note 96931 added to function.strlen
Groups: php.notes 
Request: Send a blank email to php-notes+get-167327@lists.php.net to get a copy of this message
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. ---- Server IP: 192.41.40.227 Probable Submitter: 216.156.95.90 ---- Manual Page -- http://www.php.net/manual/en/function.strlen.php Edit -- https://master.php.net/note/edit/96931 Del: integrated -- https://master.php.net/note/delete/96931/integrated Del: useless -- https://master.php.net/note/delete/96931/useless Del: bad code -- https://master.php.net/note/delete/96931/bad+code Del: spam -- https://master.php.net/note/delete/96931/spam Del: non-english -- https://master.php.net/note/delete/96931/non-english Del: in docs -- https://master.php.net/note/delete/96931/in+docs Del: other reasons-- https://master.php.net/note/delete/96931 Reject -- https://master.php.net/note/reject/96931 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167327) next »