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)
set names utf8
utf8 has no horizontal bars in the middle and no single quotes