将我的网站移动到新的服务器时,发现了以下问题:来自mysql的“奇怪”字符(ê,ç,ã等)的呈现出现错误。为什么使用相同的数据会得到不同的结果?
例如:
MySQL的:加洛VAI最终,apóscobranças德pênaltis。
旧服务器(apache 2.2/php 5.3): Galo vai a final,apóscobrançasdepênaltis。 (正确)
新的服务器(Apache的2.4/PHP的5.4): 加洛VAI最终,apóscobranças德pênaltis。 (错)
我相信,无论是Apache或PHP是造成这一点,但我还没有找到关于它在任何地方的文件。
有人能帮我找到这个错误的原因吗?
编辑
这里呈现此代码(注意,这是相同的两个服务器):
控制器:
//Noticias
$q = Doctrine_Query::create()
->select("id,titulo,thumb,conteudo")
->from('noticia')
->limit(10)
->where("data <= '$today'")
->andWhere("status = 1")
->andWhere("categoria_id = 1")
->orderby('data DESC');
$res = $q->fetchArray();
foreach($res as $key => $value){
$res[$key]['titulo'] = stripslashes($res[$key]['titulo']);
$res[$key]['conteudo'] = strip_tags($res[$key]['conteudo']);
$res[$key]['conteudo'] = stripslashes($res[$key]['conteudo']);
$res[$key]['conteudo'] = substr($res[$key]['conteudo'],0,150) . '...';
}
$smarty -> assign('noticias',$res);
查看:
<ul class="homelist">
{foreach item=noticia from=$noticias name=news}
<li> <a href="noticia/{$noticia.id}/{$noticia.titulo|slug}/"><img src="assets/images/noticias/{$noticia.thumb}" alt="" /></a> <a class="title" href="noticia/{$noticia.id}/{$noticia.titulo|slug}/">{$noticia.titulo}</a>
<p>{$noticia.conteudo}</p>
<a class="more" href="noticia/{$noticia.id}/{$noticia.titulo|slug}/">more</a>
</li>
{/foreach}
<li><p align="center"><a href="/noticias/1">Veja mais</a></p> </li>
</ul>
不正确的编码。检查apache的编码设置 – DevZer0
你的字符集是什么? – silentw
http://www.php.net/manual/en/function.htmlspecialchars.php#112476 '从PHP 5.4开始,它们将默认编码从“ISO-8859-1”更改为“值得查看的UTF-8”作为可能的原因? – Flosculus