note 39535 deleted from function.substr by aidan

From: Date: Sun, 22 Aug 2004 11:19:21 +0000
Subject: note 39535 deleted from function.substr by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75097@lists.php.net to get a copy of this message
Note Submitter: windix at 263 dot net ---- Here is a function to handle UTF-8 strings, for someone who can't use mb_substr like me. <?php /* UTF-8 version of substr(), for people who can't use mb_substr() like me. Length is not the count of Bytes, but the count of UTF-8 Characters Author: Windix Feng Bug report to: windix(AT)263.net, http://www.douzi.org/blog - History - 1.0 2004-02-01 Initial Version 2.0 2004-02-01 Use PREG instead of STRCMP and cycles, SPEED UP! */ function utf8_substr($str,$start) { preg_match_all( "/[\x01-\x7f]| [\xc2-\xdf][\x80-\xbf]| \xe0[\xa0-\xbf][\x80-\xbf]| [\xe1-\xef][\x80-\xbf][\x80-\xbf]| \xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]| [\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $str, $ar); if(func_num_args() >= 3) { $end = func_get_arg(2); return join("",array_slice($ar[0],$start,$end)); } else { return join("",array_slice($ar[0],$start)); } } ?>

« previous php.notes (#75097) next »