本文介绍了PHP中的UTF-8编码问题,特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试重新创建一个字符串,但是utf-8编码出现问题(我想是吗?)
I am trying to recreate a string but I am having issues with the utf-8 encoding (I guess?)
我正在使用下面的代码来格式化字符串
I am using the code below to format a string
$pre_subject = (strip_tags(html_entity_decode($temp_subject)));
$pre_subject = str_replace('Â', '', $pre_subject);
$pre_subject = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $pre_subject);
问题在于,我得到的不是第二句的结果,而是下面的第一句的结果.
The problem is that instead of getting the result as in the 1st sentence below, I get a result as the second one.
1st. summary: SHANGHAI room - Réunion
2nd. summary: SHANGHAI room - R'eunion
我需要保留格式作为第一个示例,如何修改我的代码?
I need to keep the format as the first example, how can I modify my code for that?
推荐答案
该字符串包含UTF-8字符.您需要对它们进行解码,或者告诉正在读取的内容以使用UTF-8编码.
The string has UTF-8 characters. You need to either decode them, or tell whatever is reading it to use UTF-8 encoding.
所以,这个:
$pre_subject = (strip_tags(html_entity_decode($temp_subject)));
$pre_subject = str_replace('Â', '', $pre_subject); // if this was trying to fix the problem, remove it
$pre_subject = utf8_decode($pre_subject);
或将其添加到<head>
:
<meta charset="utf-8">
这篇关于PHP中的UTF-8编码问题,特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!