Reputation: 121
please help find error. i get from mysql several strings. these strings contains cyrillic symbols.
<?php
header("Content-type: text/html; charset=utf-8");
error_reporting(0);
require('connectDB.php');
$connect = mysql_connect($host,$user,$password);
mysql_query("SET NAMES utf8");
mysql_select_db($database);
$sql = 'SELECT `title` FROM `graphs`';
$result = mysql_query($sql); // or die(mysql_error());
$response = array();
if($result){
while($row = mysql_fetch_array($result)) {
$response[] = $row["title"];
};
}
else{
$response = 'error';
}
print_r($response);
print(json_encode($response));
?>
but first print operator output follow:
Array ( [0] => ыва [1] => ввв [2] => ываываывавы )
second print operator output follow:
["\u044b\u0432\u0430","\u0432\u0432\u0432","\u044b\u0432\u0430\u044b\u0432\u0430\u044b\u0432\u0430\u0432\u044b"]
i try all files resave with ebcoding utf8 without BOM
Upvotes: 2
Views: 386
Reputation: 642
Try to do like below:
json_encode($response, JSON_UNESCAPED_UNICODE);
Upvotes: 2