note 44838 added to function.substr

From: Date: Tue, 17 Aug 2004 18:59:15 +0000
Subject: note 44838 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-79843@lists.php.net to get a copy of this message
Regarding windix's function to handle UTF-8 strings: one can use the "u" modifier on the regular expression so that the pattern string is treated as UTF-8 (available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32). This way the function works for other encodings too (like Greek for example). The modified function would read like this: function utf8_substr($str,$start) { preg_match_all("/./u", $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)); } } ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44838 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44838&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44838&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#79843) next »