Reputation: 55
I have a problem with charset. On russian language I've saw symbol �
<meta>
is UTF-8 , in DB charset utf8_general_ci , take data from DB with functions
substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 290) . '..'
what's the problem? what do you think?
Upvotes: 0
Views: 213
Reputation: 39724
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));
}
Upvotes: 2