Update string.utils.php

This commit is contained in:
Namhyeon Go 2019-09-11 11:38:34 +09:00 committed by GitHub
parent 588301c29f
commit 2aadb4cf0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);