我需要一些帮助来获取 MySQL 表来存储和输出来自以下语言的字符:
- 英语
- 法语
- 俄语
- 土耳其语
- 德语
这些是我在数据中知道的语言。它还使用如下数学符号:
b ∈ A. Define s(A):= supn≥0 r A (n) for each A ⊆ ? ∪ {0}.
我正在使用 htmlentities 对文本进行编码。上面的 ? 旨在显示为 ℕ。 当我查看 PhpMyAdmin 中的数据时,它以这种方式显示。其他字符按预期编码。
表格设置为 utf8_unicode_ci,网站的所有方面都设置为 UTF-8(包括通过 .htaccess 文件、PHP header 和元数据标签)。
请帮忙?
附加信息:
托管环境:
Linux, Apache
Mysql 5.5.38
PHP Version 5.4.4-14
连接字符串:
ini_set('default_charset', 'UTF-8');
$mysqli = new mysqli($DB_host , $DB_username, $DB_password);
$mysqli->set_charset("utf8");
$mysqli->select_db($DB_name);
显示创建表 mydatabase.mytable 输出:
CREATE TABLE `tablename` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
`product` int(11) NOT NULL,
`ppub` tinytext COLLATE utf8_unicode_ci NOT NULL,
`pubdate` date NOT NULL,
`numerous_other_tinytext_cols` tinytext COLLATE utf8_unicode_ci NOT NULL,
`numerous_other_tinytext_cols` tinytext COLLATE utf8_unicode_ci NOT NULL,
`text` text COLLATE utf8_unicode_ci NOT NULL,
`keywords` tinytext COLLATE utf8_unicode_ci NOT NULL,
`active` int(11) NOT NULL DEFAULT '1',
`orderid` int(11) NOT NULL,
`src` tinytext CHARACTER SET latin1 NOT NULL,
`views` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=17780 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
SELECT DEFAULT_CHARACTER_SET_NAME FROM information_schema.SCHEMATA 输出:
DEFAULT_CHARACTER_SET_NAME
utf8 [->UTF-8 Unicode]
utf8mb4 [->UTF-8 Unicode]
使用的字体:
Arial
数据库中的文本示例:
Let <em>A</em> be a subset of the set of nonnegative integers ℕ ∪ {0}, and let <em>r</em><sub><em>A</em></sub> (<em>n</em>) be the number of representations of <em>n</em> ≥ 0 by the sum <em>a</em> + <em>b</em> with <em>a, b</em> ∈ <em>A</em>.
网页输出:
Let <em>A</em> be a subset of the set of nonnegative integers ? ∪ {0}, and let <em>r</em><sub><em>A</em></sub> (<em>n</em>) be the number of representations of <em>n</em> ≥ 0 by the sum <em>a</em> + <em>b</em> with <em>a, b</em> ∈ <em>A</em>.
变成了
让 A 成为非负整数集的子集? ∪ {0}, 令 rA (n) 为 n ≥ 0 的表示的数量 a + b 和 a, b ∈ A.
最佳答案
虽然您的数据库和表配置为使用 UTF-8,但您的其中一列仍然不是:
CREATE TABLE `tablename` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`created` datetime NOT NULL,
`updated` datetime NOT NULL,
`product` int(11) NOT NULL,
`ppub` tinytext COLLATE utf8_unicode_ci NOT NULL,
`pubdate` date NOT NULL,
`numerous_other_tinytext_cols` tinytext COLLATE utf8_unicode_ci NOT NULL,
`numerous_other_tinytext_cols` tinytext COLLATE utf8_unicode_ci NOT NULL,
`text` text COLLATE utf8_unicode_ci NOT NULL,
`keywords` tinytext COLLATE utf8_unicode_ci NOT NULL,
`active` int(11) NOT NULL DEFAULT '1',
`orderid` int(11) NOT NULL,
`src` tinytext CHARACTER SET latin1 NOT NULL, <--------- This one
`views` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=17780 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
由于所有其他符号都经过 HTML 编码,因此它们将在所有字符集中存在,但 ℕ
不会存在,它没有命名实体引用。
您需要转换您的列:
ALTER TABLE tablename MODIFY src TINYTEXT CHARACTER SET utf8;
注意:我注意到您喜欢数学符号。其中一些在基本多语言平面之外,即。代码点 > 0xFFFF,例如 mathematical letter variants (fraktur, double-struck, semantic italic etc.) .
如果你想支持它们,你需要将MySQL中所有地方(表,列,连接)的编码切换为utf8mb4
,这是真正的UTF-8(utf8
在 MySQL 中表示 UTF-8 的子集,仅包含 BMP),带有 utf8mb4_unicode_ci
排序规则。 Here is how to do the migration.
此外,我注意到您正在对 HTML 进行 HTML 编码。也许你有理由,但我认为存储它没有意义:
<em>A</em>
如果要将其放入 HTML 文档中,现在至少需要对其进行 HTML 解码一次,有时需要两次。我宁愿存储几乎所有人都做的事情:
<em>A</em>
这样,您将以最佳方式在本地存储 Unicode 字符。
关于多种欧洲语言的MySQL字符集+数学符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25484400/