繁体   English   中英

如何将Windows-1252字符转换为php中的值?

[英]How to convert Windows-1252 characters to values in php?

我们有几个包含Windows-1252字符的数据库字段:

an example pain— if you’re

这些值映射到此列表中的所需值:

http://www.i18nqa.com/debug/utf8-debug.html

我尝试了各种htmlentites,mb_detect_encoding,uft8_decode等的排列,但还没有能够将这些值转换为:

一个例子的痛苦 - 如果你是

如何将这些字符转换为php中列出的值?

您可以使用mb_convert_encoding

$str = "an example pain— if you’re";
$str = mb_convert_encoding($str, "Windows-1252", "UTF-8");
echo $str;
//an example pain— if you’re

DEMO:
http://ideone.com/NsIb5x

哦,天啊,这需要太长时间才能解决,所以我想在这里发布我的答案,因为这个链接不断出现在搜索中。 我的MySQL数据库表的编码为utf8mb4_unicode_520_ci,列中有令人烦恼的工作卷曲引号。 我试图读取数据库值并使用json_encode进行编码,但它会失败并且json_encode将返回空白,因此我使用了utf8_encode。 这不正确地改变了角色。 我不得不使用mb_convert_encoding从Windows-1252转到UTF-8,但是json_encode也搞砸了。 最后,这工作:

$file = urlencode(mb_convert_encoding ($stringwithcurlyquotes, "UTF-8", 'Windows-1252'));

由于我遇到了图片网址的问题,这非常有效,并且不要求我在另一边解码它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM