我在使用 PHP rest api 时遇到了一个问题。我无法以任何方式显示 unicode 输出。
表'coronaapi'数据:
身份证标题
1 কুমিল্লা সদর</p>
2 কুমিল্লা সদর দক্ষিণ
<?php
// Headers
header('Access-Control-Allow-Origin: *');
header('Content-type: text/html; charset=UTF-8');
header('Content-Type: application/json');
include_once '../../config/Database.php';
include_once '../../models/Post.php';
// Instantiate DB & connect
$database = new Database();
$db = $database->connect();
// Instantiate blog post object
$post = new Post($db);
// Blog post query
$result = $post->read();
// Get row count
$num = $result->rowCount();
// Check if any posts
if($num > 0) {
// Post array
$posts_arr = array();
// $posts_arr['data'] = array();
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
extract($row);
$post_item = array(
'id' => $id,
'title' => $title,
'body' => $body,
'author' => $author,
'category_id' => $category_id,
//'category_name' => $category_name
);
// Push to "data"
array_push($posts_arr, $post_item);
// array_push($posts_arr['data'], $post_item);
}
// Turn to JSON & output
echo json_encode($posts_arr);
} else {
// No Posts
echo json_encode(
array('message' => 'No Posts Found')
);
}
输出显示如下:
[{"id":"1","title":"???????? ???","body":"???","author":"00","category_id":"sodor"},{"id":"2","title":"???????? ??? ??????","body":"03","author":"00","category_id":"sadardokkhin"}]
但我想显示
[{"id":"1","title":"কুমিল্লা সদর","body":"???","author":"00","category_id":"sodor"},{"id":"2","title":"কুমিল্লা সদর দক্ষিণ","body":"03","author":"00","category_id":"sadardokkhin"}]