summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/utf8.php15
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()