<?php
require_once('config.php');
require_once 'convertArraytoJson.php';
$connection=mysql_connect ( "localhost", $databaseuser, $databasepassword );
//mysql_set_charset('utf8'); //Is this better than the last line?
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'"); //Which one is better?
@mysql_select_db ($databasename) or die ( "Unable to select database" );
$query="SELECT `Building` FROM `tablebuilding` WHERE ID=51";
$data = mysql_query($query);
while (true){
$info = mysql_fetch_array ( $data, MYSQL_ASSOC );
if ($info == false) {
break;
}
$output = $info['Building'];
}
//$output is FX Lifestyle X’nter
$v= htmlspecialchars ($output); //Should I use this?
$result = json_encode($output);
//$result is FX Lifestyle X\u2019nter
echo ($result);
?>
Just want to verify is this the right way?
What's the difference between mysql_set_charset('utf8')
and mysql_query("SET character_set_results = 'utf8', character_set_client = 开发者_开发百科'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
and which one are better.
JSON is just a open standard for data interchange. If you send your json encoded string, the client will convert your string whith the correct charset if it supports JSON. Try to use the client JavaScript interpreter and check if your client supports JSON:
echo "<script>document.write('$result');</script>";
精彩评论