问问题
201 次
1 回答
2
That is because you have Unicode characters and you are subtracting exactly in a wrong place and that letter cannot be rendered anymore.
Instead you should subtract by spaces, eg:
echo implode(' ', array_slice(explode(' ', strip_tags(html_entity_decode($sentence, ENT_QUOTES, 'UTF-8'))), 0, 50)); // for 50 words
or use substr_unicode:
function substr_unicode($str, $s, $l = null) {
return join("", array_slice(
preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY), $s, $l));
}
于 2012-09-18T14:20:29.823 回答