From 7077c942d02aa54639938e051041ca956224be12 Mon Sep 17 00:00:00 2001 From: andi <andi@splitbrain.org> Date: Sun, 23 Jan 2005 17:33:44 +0100 Subject: [PATCH] utf8 substr replacement darcs-hash:20050123163344-9977f-38c3f78a3b76ab0e7f181698cb79711b5d3469c1.gz --- inc/utf8.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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() -- GitLab