Solve the problem of gbk Chinese garbled characters passed to JavaScript and json_encode through the PHP array-jerrylsxu first created a JSON function about gbk Chinese garbled characters in json_encode.
/*************************************** * *********************** Use a specific function to process all elements in the array * @ param string & $ array the string to be processed * @ param string $ function the function to be executed * @ return boolean $ apply_to_keys_also is also applied to the key * @ access public ******** **************************************** * ************/function arrayRecursive (& $ array, $ function, $ apply_to_keys_also = false) {foreach ($ array as $ key => $ value) {if (is_arr Ay ($ value) {arrayRecursive ($ array [$ key], $ function, $ apply_to_keys_also );} else {$ array [$ key] = $ function ($ value);} if ($ apply_to_keys_also & is_string ($ key) {$ new_key = $ function ($ key ); if ($ new_key! = $ Key) {$ array [$ new_key] = $ array [$ key]; unset ($ array [$ key]) ;}}} /*************************************** * ************************ convert an array to a JSON string (compatible with Chinese characters) * @ param array $ array the array to be converted * @ return string the converted json string * @ access public ***************** **************************************** * ***/function JSON ($ array) {arrayRecursive ($ array, 'urlencode', true); $ json = json_encode ($ array); return urldecode ($ json );}
Database Connection value to array $ array1
$dbcnx = @mysql_connect ( "localhost", "root", "1234" );if (! $dbcnx) { echo ("Unable to connect to the " . "database server at this time."); exit ();}if (! @mysql_select_db ( "pms" )) { echo ("Unable to locate the joke " . "database at this time."); exit ();}mysql_query ( "SET NAMES 'GB2312'" ); $q=mysql_query("select * from ability where ALV = 1"); while($row=mysql_fetch_array($q)){ $array1[] = $row[AName];}
Array array1 is passed to JavaScript to array ability1