note 110742 added to function.iconv
| From: | it_informer at naver dot com | Date: | Fri, 30 Nov 2012 04:39:04 +0000 |
| Subject: | note 110742 added to function.iconv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192208@lists.php.net to get a copy of this message | ||
I needed array key & value encoding function - 'recursive_iconv', but other
recursive_iconv function can't encode array key. So wrote it myself and I'd like to share
it.
function array_iconv( $Current, $Next, $Array , $AutoDetect = true ) {
$new_array = array();
foreach($array as $key => $val) {
if(is_string($key) && ($AutoDetect == true &&
strtoupper(mb_detect_encoding($key,array($Current,$Next))) == strtoupper($Current))) {
$key = iconv($Current, $Next, $key);
}
if(is_string($val) && ($AutoDetect == true &&
strtoupper(mb_detect_encoding($val,array($Current,$Next))) == strtoupper($Current))) {
$val = iconv($Current, $Next, $val);
}
if(is_array($val)) $val = array_iconv( $Current, $Next, $val);
$new_array[$key] = $val;
}
return $new_array;
}
4rd variable($AutoDetect) is mb_detect_encoding check for prevent overwrite(?) encode the string.
----
Server IP: 69.147.83.199
Probable Submitter: 121.166.240.81
----
Manual Page -- http://www.php.net/manual/en/function.iconv.php
Edit -- https://master.php.net/note/edit/110742
Del: integrated -- https://master.php.net/note/delete/110742/integrated
Del: useless -- https://master.php.net/note/delete/110742/useless
Del: bad code -- https://master.php.net/note/delete/110742/bad+code
Del: spam -- https://master.php.net/note/delete/110742/spam
Del: non-english -- https://master.php.net/note/delete/110742/non-english
Del: in docs -- https://master.php.net/note/delete/110742/in+docs
Del: other reasons-- https://master.php.net/note/delete/110742
Reject -- https://master.php.net/note/reject/110742
Search -- https://master.php.net/manage/user-notes.php