In the Web development to often carry out the conversion of string encoding, the slightest careless will cause garbled. So it can be said that the coding problem is a big problem. After a search, we found a code for the conversion of string encoding, and then made a simple packaging, the use of more convenient.
<?phpfunction Phpcharset ($data, $to) { if (Is_array ($data)) { foreach ($data as $key + = $val) { $data [$ Key] = Phpcharset ($val, $to); } } else { $encode _array = Array ( ' ASCII ', ' UTF-8 ', ' GBK ', ' GB2312 ', ' BIG5 ' ); $encoded = mb_detect_encoding ($data, $encode _array); $to = Strtoupper ($to); if ($encoded! = $to) { $data = mb_convert_encoding ($data, $to, $encoded); } } return $data;} function ToUTF8 ($data) { return Phpcharset ($data, ' UTF-8 ');} function TOGBK ($data) { return Phpcharset ($data, ' GBK ');} function Toascii ($data) { return Phpcharset ($data, ' ASCII ');} function toGB2312 ($data) { return Phpcharset ($data, ' GB2312 ');} function ToBIG5 ($data) { return Phpcharset ($data, ' BIG5 ');}? >