diff options
author | andi <andi@splitbrain.org> | 2005-01-23 17:33:44 +0100 |
---|---|---|
committer | andi <andi@splitbrain.org> | 2005-01-23 17:33:44 +0100 |
commit | 7077c942d02aa54639938e051041ca956224be12 (patch) | |
tree | d51d283d43e4631a26631854ec642bc3fcff4940 /inc/utf8.php | |
parent | 93a9e83512a37d720cb675cbb2017e6419ea8216 (diff) | |
download | rpg-7077c942d02aa54639938e051041ca956224be12.tar.gz rpg-7077c942d02aa54639938e051041ca956224be12.tar.bz2 |
utf8 substr replacement
darcs-hash:20050123163344-9977f-38c3f78a3b76ab0e7f181698cb79711b5d3469c1.gz
Diffstat (limited to 'inc/utf8.php')
-rw-r--r-- | inc/utf8.php | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/inc/utf8.php b/inc/utf8.php index 6e015177b..3e5f5decd 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -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() |