Php code js decoding method
Php code js decoding.
1. PHP pages are encoded in Chinese and saved to the database.
2. extract data from the database and encapsulate the data in JSON format. return to the page and display Chinese characters through JS decoding.
Is there any good way for Daniel?
PHP5.2 version.
Reply to discussion (solution)
Generally, the query results are read in a loop, so there can be
while($row = mysql_assoc($rs)) { $t = array(); foreach($row as $k=>$v) $t[] = "\"$k\":\"$v\""; $res = '{' . join('},{', $t) . '}';}$json = '[' . join('],[', $res) .']';
The value of my code is as follows:
For ($ count = 0; $ row = $ result-> fetch_object (); $ count ++)
{
$ ResultArray [$ count] ['id'] = $ row-> CLIENTID;
$ ResultArray [$ count] ['Money'] = $ row-> PAYNUM;
$ ResultArray [$ count] ['title'] = $ row-> PROJECTID;
$ ResultArray [$ count] ['mobile'] = $ row-> MOBILENUM;
$ ResultArray [$ count] ['SMS _ content'] = $ row-> SMS;
$ ResultArray [$ count] ['Date'] = $ row-> CREATETIME;
}
Isn't PHP a method for automatically encapsulating JSON? Json_encode ($ resultArray). That's it.
I don't know what the purpose of this method is?
Generally, the query results are read in a loop, so there can be
while($row = mysql_assoc($rs)) { $t = array(); foreach($row as $k=>$v) $t[] = "\"$k\":\"$v\""; $res = '{' . join('},{', $t) . '}';}$json = '[' . join('],[', $res) .']';
The value of my code is as follows:
For ($ count = 0; $ row = $ result-> fetch_object (); $ count ++)
{
$ ResultArray [$ count] ['id'] = $ row-> CLIENTID;
$ ResultArray [$ count] ['Money'] = $ row-> PAYNUM;
$ ResultArray [$ count] ['title'] = $ row-> PROJECTID;
$ ResultArray [$ count] ['mobile'] = $ row-> MOBILENUM;
$ ResultArray [$ count] ['SMS _ content'] = $ row-> SMS;
$ ResultArray [$ count] ['Date'] = $ row-> CREATETIME;
}
Isn't PHP a method for automatically encapsulating JSON? Json_encode ($ resultArray). That's it.
I don't know what the purpose of this method is?
Since your php version already supports json_encode, what else do you need to ask?
Since you asked that, of course, your environment does not support the json_encode function.
Since your php version already supports json_encode, what else do you need to ask?
Since you asked that, of course, your environment does not support the json_encode function.
No, it is Chinese, and JSON cannot be used very well. on the front-end page, it is null or garbled.
Json_encode is only valid for UTF-8 encoding. you can either convert it to UTF-8 or use the method I have given.
Json_encode is only valid for UTF-8 encoding. you can either convert it to UTF-8 or use the method I have given.
Thank you. you have done it.
The process for sending Chinese data is JS-php-mysql, and the webpage is mysql-php-json-js-html.
Now my solution is,
Before data JS is transferred to PHP,
$ Html = iconv ("GB2312", "UTF-8 // IGNORE", $ html );
Before PHP-mysql
$ Html = urldecode ($ html );
Then, you can follow the normal process when getting the data. you don't need to do anything.