diff options
Diffstat (limited to 'inc/utf8.php')
-rw-r--r-- | inc/utf8.php | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/inc/utf8.php b/inc/utf8.php index 0323bed4b..ef056bfa4 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -776,15 +776,19 @@ function utf8_bad_replace($str, $replace = '') { * @author chris smith <chris@jalakai.co.uk> */ function utf8_correctIdx(&$str,$i,$next=false) { - + + if ($i <= 0) return 0; + + $limit = strlen($str); + if ($i>=$limit) return $limit; + if ($next) { - $limit = strlen($str); - while (($i<$limit) && ((ord($str[$i]) & 0xC0) == 0x80)) $i++; - } else { - while ($i && ((ord($str[$i]) & 0xC0) == 0x80)) $i--; - } - - return $i; + while (($i<$limit) && ((ord($str[$i]) & 0xC0) == 0x80)) $i++; + } else { + while ($i && ((ord($str[$i]) & 0xC0) == 0x80)) $i--; + } + + return $i; } // only needed if no mb_string available |