Min*_*int 53 php utf-8 character-encoding mojibake
我已经尝试将文本转换为utf8或从utf8转换,这似乎没有帮助.
我越来越:
"It’s Getting the Best of Me"
Run Code Online (Sandbox Code Playgroud)
它应该是:
"It’s Getting the Best of Me"
Run Code Online (Sandbox Code Playgroud)
Mat*_*hew 84
要转换为HTML实体:
<?php
echo mb_convert_encoding(
file_get_contents('http://www.tvrage.com/quickinfo.php?show=Surviver&ep=20x02&exact=0'),
"HTML-ENTITIES",
"UTF-8"
);
?>
Run Code Online (Sandbox Code Playgroud)
有关更多编码选项,请参阅mb_convert_encoding的文档.
Ben*_*Ben 28
确保你的html标头指定utf8
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Run Code Online (Sandbox Code Playgroud)
这通常对我有用(显然如果内容是utf8).
如果设置了content-type,则无需转换为html实体.
cob*_*bal 12
你的内容很好; 问题出在服务器发送的标头上:
Connection:Keep-Alive
Content-Length:502
Content-Type:text/html
Date:Thu, 18 Feb 2010 20:45:32 GMT
Keep-Alive:timeout=1, max=25
Server:Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.7 with Suhosin-Patch
X-Powered-By:PHP/5.2.4-2ubuntu5.7
Run Code Online (Sandbox Code Playgroud)
Content-Type应设置为Content-type: text/plain; charset=utf-8,因为此页面不是HTML并使用utf-8编码.Mac上的Chromium猜测ISO-8859-1并显示您描述的字符.
如果您不控制站点,请将编码指定为UTF-8,以指定用于检索内容的任何函数.我对PHP不太熟悉,不知道究竟是怎么回事.
我知道这个问题已得到解答,但设置元标记在我的案例中并没有帮助,所选答案也不够明确,所以我想提供更简单的答案.
因此,为了简单起见,将字符串存储到变量中并像这样处理
$TVrageGiberish = "It’s Getting the Best of Me";
$notGiberish = mb_convert_encoding($TVrageGiberish, "HTML-ENTITIES", 'UTF-8');
echo $notGiberish;
Run Code Online (Sandbox Code Playgroud)
哪个应该返回你想要的东西 It’s Getting the Best of Me
如果要解析某些内容,则可以在为这样的变量赋值时执行转换,其中$TVrage包含所有值的数组,此示例中的XML来自具有标记"Title"的源,该标记可能包含特殊字符,如‘或’.
$cleanedTitle = mb_convert_encoding($TVrage->title, "HTML-ENTITIES", 'UTF-8');
Run Code Online (Sandbox Code Playgroud)
小智 5
如果您在这里是因为您在WordPress网站中遇到垃圾字符问题,请尝试以下方法:
打开 wp-config.php
评论define('DB_CHARSET', 'utf8')和define('DB_COLLATE', '')
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
//define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
//define('DB_COLLATE', '');
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
81076 次 |
| 最近记录: |