本文介绍了将 MySQL 表中的 HTML 外来字符转换为 utf-8 字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 MySQL 和使用 utf-8 有问题,我最终使用了 HTML 字符,但我开始非常后悔.我现在有 4 个表格,其中有很多外来字符保存为 HTML.

I have had issues with my MySQL and using utf-8 and I ended up using HTML characters, but I am starting to regret that very much. I now have 4 tables with a lot of foreign characters saved as HTML.

我已经能够重写编程并设置 MySQL 以正确处理 utf-8,但是将字符串转换为 utf-8 的最佳方法是什么?

I have been able to rewrite programming and setup MySQL to process utf-8 properly, but what would be the best way to convert the strings to utf-8?

INSERT INTO `languages` (`id`, `title`, `native`, `alias`, `status`, `weight`, `updated`, `created`) VALUES
(1, 'English', 'English', 'en', 1, 1, '2009-11-02 21:37:38', '2009-11-02 20:52:00'),
(2, 'Dutch', 'Nederlands', 'nl', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(8, 'French', 'Français', 'fr', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(3, 'Spanish', 'Español', 'es', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(4, 'Italian', 'Italiano', 'it', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(6, 'German', 'Deutsch', 'de', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(7, 'Portuguese', 'Português', 'pt', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(11, 'Swedish', 'Svenska', 'sv', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(9, 'Polish', 'Polski', 'pl', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(12, 'Russian', 'Русский', 'ru', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(13, 'Afrikaans', 'Afrika', 'af', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(14, 'English', 'English', 'en', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(15, 'Albanian', 'Shqip', 'sq', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(16, 'Arabic', 'العربية', 'ar', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(17, 'Farsi', 'الفارسية', 'fa', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(18, 'Chinese (traditional)', '中文(繁體)', 'cht', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(19, 'Japanese', '日本', 'ja', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(20, 'Latin', 'Latina', 'la', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(21, 'Chinese (simplified)', '中文(简体)', 'chs', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(22, 'Turkish', 'Türkçe', 'tr', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(23, 'Catalan', 'Català', 'ca', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(24, 'Hindi', 'हिन्दी', 'hi', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(25, 'Hungarian', 'Magyar', 'hu', 1, NULL, '0000-00-00 00:00:00', '0000-00-00 00:00:00');

以上是 SQL 数据的示例.

Above is an example of SQL data.

推荐答案

通过 PHP 来回数据.做一个选择,抓取相关字段并通过 htmlentities() 运行它们以转换回实际字符​​,然后将数据填回数据库.

Round trip the data through PHP. Do a select, grab the relevant fields and run them through htmlentities() to convert back into actual characters, then stuff the data back into the database.

MySQL 本身没有任何实体编码/解码支持,因此进行往返是最快/最简单的解决方法.

MySQL itself doesn't have any entity encoding/decoding support, so doing the round trip is the quickest/easiest fix.

这篇关于将 MySQL 表中的 HTML 外来字符转换为 utf-8 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 02:48