utf8 substr replacement

darcs-hash:20050123163344-9977f-38c3f78a3b76ab0e7f181698cb79711b5d3469c1.gz
This commit is contained in:
andi 2005-01-23 17:33:44 +01:00
parent 93a9e83512
commit 7077c942d0
1 changed files with 15 additions and 0 deletions

View File

@ -69,6 +69,21 @@ function utf8_strlen($string){
return count($uni);
}
/**
* This is a unicode aware replacement for substr()
*
* Uses mb_string extension if available
*
* @author Andreas Gohr <andi@splitbrain.org>
* @see substr()
*/
function utf8_substr($str, $start, $length=null){
if(!defined('UTF8_NOMBSTRING') && function_exists('mb_substr'))
return mb_substr($str,$start,$length,'utf-8');
$uni = utf8_to_unicode($str);
return unicode_to_utf8(array_slice($uni,$start,$length));
}
/**
* This is a unicode aware replacement for strtolower()