jsonp - The background php returns json. The local test Chinese display is normal, but the server Chinese becomes a question mark.
过去多啦不再A梦
过去多啦不再A梦 2017-05-16 13:01:57
0
1
564

The back-end PHP gets the data from the MySQL database, and the output is in json format and transmitted to the front desk. The PHP files on the local and server are connected to the same database. During the local test, the json return data is normal in Chinese, and the json return data on the server is Chinese. Become a question mark

Database encoding and structure

< /p>

conn.php connection database file

<?php
    $dbName = "Library Name";
    $conn = @ mysql_connect("database address", "username", "password") or die("database link error");
    mysql_query("set names 'utf-8 "); //Use utf encoding;
    $flag = mysql_select_db($dbName, $conn);
     
      
    function toHtmlcode($content)
    {
        return $content = str_replace("\n","<br>",str_replace(" ", " ", $content));
    }
?>

get.php gets data and sends json

<?php
header('Content-type:application/json;charset=utf-8');
include 'conn.php';
$rs = mysql_query('select * from msg');
$result = array();
while($row = mysql_fetch_object($rs)){
    array_push($result, $row);
}
$json = json_encode($result,JSON_UNESCAPED_UNICODE);
echo $json;
?>

Local test Chinese is normal (phpstudy environment, php5.4.45)

The Chinese test on the server is full of question marks (Alibaba Cloud web hosting, php5.4.45)

过去多啦不再A梦
过去多啦不再A梦

reply all(1)
淡淡烟草味

set names utf8
utf8 has no horizontal bars in the middle and no single quotes

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template