【问题标题】:php code not outputting utf 8 characters?php代码不输出utf 8个字符?
【发布时间】:2016-04-02 17:14:46
【问题描述】:

我将数据库设置为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);
    }

}

【问题讨论】:

  • PHP 当然在这里输出任何未经修改的字符串,这不是问题。问题是您发送给客户的字符编码是什么,以及您的客户是否使用实际上具有这些字符字形的字体。
  • UTF-8 all the way through的可能重复
  • 表格/列可能是CHARACTER SET latin1。让我们看看SHOW CREATE TABLE
  • 你试过SET NAMES UTF8查询吗?

标签: php mysql json utf-8


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多