php代码不输出utf 8字符?

标签 php mysql json utf-8

我的数据库设置为 UTF8 GENERAL CI 作为我的表的排序规则。但是当我尝试使用以下 PHP 代码进行输出时,问号出现在 UTF 字符的位置(我正在尝试打印区域语言字符)...

以下是我的代码:

<?php
class Article implements JsonSerializable{
    private $id;
    private $title;
    private $content;

    public function getId() {
        return $this->id;
    }

    public function getTitle() {
        return $this->title;
    }

    public function getContent() {
        return $this->content;
    }

    public static function getById($id) {
        $db = newMysqli ();
        $query = "select * from articles where _id=?";
        $stmt = $db->prepare ( $query ) or dieOnError ( $db );
        $stmt->bind_param ( "i", $id ) or dieOnError ( $db );
        $stmt->execute () or dieOnError ( $db );

        $member = new Article();
        $stmt->bind_result ( $member->id, $member->title, $member->content);
        $stmt->fetch () or dieOnError ( $db );
        $stmt->close ();
        return $member;
    }

    public function jsonSerialize(){
        return get_object_vars($this);
    }

}

最佳答案

尝试将文件编码更改为UTF-8。 (Notepad++ 中的编码菜单 -> 转换为 UTF-8)

关于php代码不输出utf 8字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36376368/

相关文章:

mysql - 使用正则表达式搜索并替换 Mysql 中的 JSON

javascript - 将两个 JSON 值合并为一个数组

php - 忽略 MySQL 查询中的空 "$_POST"值

javascript - 我们可以将对象作为参数传递到类似sql的数组中,以防止使用promise-mysql模块在nodejs中进行sql注入(inject)吗

php - 将mysql数据库中的一行值添加到动态表中

php - php上的访问被拒绝错误

php: 在某些情况下避免使用 __get?

php - PHP strtotime 函数的奇怪行为

php - 当我向下滚动时,图像下降

javascript - 使用 Node 从 CL 创建存储库时出现 Github API 错误,JSON 解析错误