不正确的字符集

时间:2012-09-18 14:12:32

标签: php html character-encoding

我遇到charset问题。在俄语中,我看到了符号

<meta> UTF-8 ,在数据库字符集 utf8_general_ci 中,从数据库获取数据使用功能

substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 290) . '..'

有什么问题?你觉得怎么样?

1 个答案:

答案 0 :(得分:2)

那是因为你有Unicode字符而且你正在错误的地方减去,而且这封信不能再渲染了。

相反,你应该用空格减去,例如:

echo implode(' ', array_slice(explode(' ', strip_tags(html_entity_decode($sentence, ENT_QUOTES, 'UTF-8'))), 0, 50)); // for 50 words

或使用substr_unicode

function substr_unicode($str, $s, $l = null) {
    return join("", array_slice(
        preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY), $s, $l));
}