【发布时间】:2013-12-20 21:21:21
【问题描述】:
我需要限制字符串的长度。我是这样做的:
$str.='<div class="timt">'.substr($row['summary'],0,180).'</div>';
问题在于,在我的语言中,有一些特殊字符,例如 áéíúó ,当字符串以特殊字符“结束”时,行尾会回显 h&eac 而不是 hé。
我认为这是因为&eacute 或类似的东西......但我该如何解决这个问题,所以这不会被“截断”?
我找到了一些建议,但没有一个有效How to truncate HTML with special characters?.. 有没有人可以指出我该如何解决这个问题。
我也试过了,但是没用。
$str.='<div class="timt">'.mb_strcut($row['summary'],0,180,"UTF-8").'</div>';
在安德烈的回答之后我试试这个
$description = html_entity_decode($row['summary']);
$str.='<div class="timedesctt" onclick="location.href=\''.$this->make_url("item/view/".$row['itemid'],array('city_name'=>$this->get_english_city_name($row['city']))).'\';">'.mb_strcut($description,0,180,"UTF-8").'</div>';
现在只是有问题.. 它显示 ? 而不是 á
我的数据库编码为 utf8 unicode ci,字符集设置为 utf8
解决方案:html_entity_decode($strint,ENT_QUOTES, 'UTF-8')
【问题讨论】:
标签: php string special-characters