Php code js decoding

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.