【问题标题】:How to get rid of the special characters getting from the database using smarty? [duplicate]如何摆脱使用 smarty 从数据库中获取的特殊字符? [复制]
【发布时间】:2016-08-06 07:57:51
【问题描述】:

我的一些直接来自 MySQL 数据库的内容显示为 ’— 字符。

我猜在将数据插入数据库时​​,我错误地使用了 SET NAMES utf-8 而不是 SET NAMES utf8。特殊字符未正确转换并按原样显示。

为了避免这些,我在<head> 标签..
<meta http-equiv="Content-Type" content="text/html";charset=UTF-8" /> 之间的页面中使用了以下内容。

但它没有用。

如何在页面中显示时将这些转换为原始字符?

【问题讨论】:

    标签: php utf-8 character-encoding special-characters


    【解决方案1】:

    试试这个功能

    function charConversion($string, $to = "HTML-ENTITIES", $from = 'UTF-8,ASCII,ISO-8859-9,ISO-8859-1') {
        $str = mb_convert_encoding($string, $to, $from);
        $str = stripslashes($str);
        if (empty($str)) {
            return $string;
        }
        return $str;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 2014-01-20
      • 1970-01-01
      • 2017-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多