[英]Why do I get a different timecode when using the same value in a variable?
[英]Why do I get a different result using the same data?
將我的網站移動到新服務器時,發現以下問題:來自mysql的“奇怪”字符(ê,ç,ã等)的呈現被錯誤地呈現。
例如:
MySQL:Galo vai決賽,大約是pónaltis的cobranças。
舊服務器(apache 2.2 / php 5.3): Galo vai最終版,apóscobrançasdepênaltis。 (正確)
新服務器(apache 2.4 / php 5.4): Galo vai最終版本,apcoscobrançasdepª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>
您必須手動將編碼更改為“ ISO-8859-1”。 在5.4之前,默認編碼為“ UTF-8”。 使用此代碼:
htmlspecialchars($string, ENT_COMPAT,'ISO-8859-1', true)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.