diff --git a/helper/string.utils.php b/helper/string.utils.php index f152505..f219f43 100644 --- a/helper/string.utils.php +++ b/helper/string.utils.php @@ -59,7 +59,7 @@ if(!check_function_exists("get_formatted_number")) { } if(!check_function_exists("get_cutted_string")) { - function get_cutted_string($str, $start, $len=0, $charset="utf-8") { + function get_cutted_string($str, $start, $len=null, $charset="utf-8") { $result = ""; if(check_function_exists("iconv_substr")) { @@ -74,6 +74,41 @@ if(!check_function_exists("get_cutted_string")) { } } +if(check_function_exists("get_string_length")) { + function get_string_length($str, $charset="utf-8") { + $len = 0; + + if(check_function_exists("iconv_strlen")) { + $len = iconv_strlen($str, $charset); + } elseif(check_function_exists("mb_strlen")) { + $len = mb_strlen($str, $charset); + } else { + $len = strlen($str); + } + + return $len; + } +} + +if(!check_function_exists("get_splitted_strings")) { + function get_splitted_strings($str, $len=32, $chsarset="utf-8") { + $strings = array(); + + $_len = get_string_length($str); + $_pos = 0; + while($_len > $_pos) { + $strings[] = get_cutted_string($str, $_pos, $len, $charset); + $_pos += $len; + + if($_pos >= $_len) { + $strings[] = get_cutted_string($str, $_pos); + } + } + + return $strings; + } +} + if(!check_function_exists("split_by_line")) { function split_by_line($str) { return preg_split('/\n|\r\n?/', $str);