note 110742 deleted from function.iconv by googleguy

From: Date: Fri, 30 Nov 2012 04:41:36 +0000
Subject: note 110742 deleted from function.iconv by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192209@lists.php.net to get a copy of this message
Note Submitter: it_informer at naver dot com ---- 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.

« previous php.notes (#192209) next »