PHP automatically identifies the original encoding and encodes the string.
This example describes how PHP can automatically identify the original encoding and encode and convert strings. We will share this with you for your reference. The details are as follows:
/*** Encode and convert data * @ param array/string $ data array * @ param string $ encoding after output conversion * Created on 2016-7-13 */function array_iconv ($ data, $ output = 'utf-8') {$ encode_arr = array ('utf-8', 'ascii ', 'gbk', 'gb2312', 'big5 ', 'jis ', 'eucjp-win', 'sjis-win', 'euc-JP'); $ encoded = mb_detect_encoding ($ data, $ encode_arr); if (! Is_array ($ data) {return mb_convert_encoding ($ data, $ output, $ encoded);} else {foreach ($ data as $ key => $ val) {$ key = array_iconv ($ key, $ output); if (is_array ($ val) {$ data [$ key] = array_iconv ($ val, $ output );} else {$ data [$ key] = mb_convert_encoding ($ data, $ output, $ encoded) ;}} return $ data ;}}