Update string.utils.php
This commit is contained in:
parent
c11f8d32ec
commit
9508d3f2b7
|
@ -7,9 +7,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(!check_function_exists("get_converted_string")) {
|
if(!check_function_exists("get_converted_string")) {
|
||||||
function get_converted_string($str, $to_charset, $from_charset) {
|
function get_converted_string($str, $to_charset="detect", $from_charset="detect") {
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
||||||
|
// detect charset (input)
|
||||||
if($form_charset == "detect") {
|
if($form_charset == "detect") {
|
||||||
if(check_function_exists(array("mb_detect_encoding", "mb_detect_order"))) {
|
if(check_function_exists(array("mb_detect_encoding", "mb_detect_order"))) {
|
||||||
$from_charset = mb_detect_encoding($str, mb_detect_order(), true);
|
$from_charset = mb_detect_encoding($str, mb_detect_order(), true);
|
||||||
|
@ -18,7 +19,30 @@ if(!check_function_exists("get_converted_string")) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(check_function_exists("iconv")) {
|
// detect charset (output)
|
||||||
|
if($to_charset == "detect") {
|
||||||
|
if(check_function_exists("mb_internal_encoding")) {
|
||||||
|
$from_charset = mb_internal_encoding();
|
||||||
|
} elseif(check_function_exists("iconv_get_encoding")) {
|
||||||
|
$from_charset = iconv_get_encoding("internal_encoding");
|
||||||
|
} else {
|
||||||
|
$_candidates = array(
|
||||||
|
ini_get("default_charset"),
|
||||||
|
ini_get("iconv.internal_encoding"),
|
||||||
|
ini_get("mbstring.internal_encoding"),
|
||||||
|
"UTF-8"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// normalize charset (UPPERCASE)
|
||||||
|
$from_charset = strtoupper($from_charset);
|
||||||
|
$to_charset = strtoupper($from_charset);
|
||||||
|
|
||||||
|
// test conditions
|
||||||
|
if($from_charset == $to_charset) {
|
||||||
|
$result = $str;
|
||||||
|
} elseif(check_function_exists("iconv")) {
|
||||||
$result = iconv($from_charset, $to_charset, $str);
|
$result = iconv($from_charset, $to_charset, $str);
|
||||||
} elseif(check_function_exists("mb_convert_encoding")) {
|
} elseif(check_function_exists("mb_convert_encoding")) {
|
||||||
$result = mb_convert_encoding($str, $to_charset, $from_charset);
|
$result = mb_convert_encoding($str, $to_charset, $from_charset);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user