数据库中有诸如Â等的符号,该怎么办? [英] There are symbols like  and so on in database, what to do?

查看:182
本文介绍了数据库中有诸如Â等的符号,该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的描述中有一些符号,例如â€等.我能做些什么吗?还是如果它在数据库中,我现在什么也不能做?

I have a few symbols in my description like  ⠀ and so on. Can I do anything about it? Or if it's in database, I can't do nothing now?

推荐答案

这实际上取决于问题所在.

It sort of depends what the problem actually is...

如果这些字符被假定存在(例如西班牙语中的Mañana"),那么您需要确保所有字符都位于UTF-8中……最好的方法是:

If it's that those characters are supposed to be there (such as "Mañana" in Spanish) then you'll need to ensure everything is in UTF-8... the best way is to:

1:检查数据库表是否采用"utf-8"编码(如果未将其转换为utf-8)

1: check the database tables are in "utf-8" encoding (if not convert them to utf-8)

2:如Martin所述,请使用以下类似方法确保数据库连接器为utf-8:

2: as Martin noted, ensure the database connector is utf-8 using something like:

mysql_set_charset('utf8'); //note that MySQL uses no hyphen here

3:确保文档为utf-8(可以在顶部添加标题)

3: ensure the the document is utf-8 (you can add a header at the top)

<?php header('Content-type:text/html;charset=utf-8'); ?>

4:出于安全考虑,也将其添加为meta标签

4: just to be on the safe side, add it in as a meta tag as well

<meta http-equiv="content-type" content="text/html;charset=utf-8" />


如何

很可能您在数据库中有一些达芙字符,其中ISO-8859-1之类的东西已经很糟糕地混为UTF-8.在这种情况下,您会注意到诸如£之类的东西,而您真正想要的是£(因为UTF-8字符包含的数据比ISO-8859-1字符多,如果您不小心,多余的数据可能会变成额外的字符.

It's quite possible you've got some duff characters in the database where something like ISO-8859-1 has been juggled to UTF-8, badly. In this case you'll notice things like £ where what you actually want is £ (because UTF-8 characters contain more data than ISO-8859-1 characters, that extra data can become an additional character if you're not careful).

在这种情况下,最好的选择是清理数据库(对于常见的错误",您可以执行类似UPDATE table SET field = REPLACE(field, '£', '£')的操作),然后将整个kaboodle转换为UTF-8(如上所述),以避免问题再次发生

In which case your best bet is to clean the database (you could probably do something like UPDATE table SET field = REPLACE(field, '£', '£') for common "errors") and then convert the whole kaboodle to UTF-8 (as outlined above) to avoid the problem recurring.

这篇关于数据库中有诸如Â等的符号,该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆