I really dont know why on cyrillic font, substring replace some characters with "?"
My Code
$string1 = get_the_content();
$string = strip_tags($string1);
$stringcutted = substr($string,0,150);
$replacement = "...";
$final = substr($stringcutted, 0, -3).$replacement;
And look how it is rendered on html
Any solution?
Because PHP's string functions are based on strings of bytes; they have no knowledge of character encoding. So in something like UTF-8, where a character can take up more than one byte, it doesn't work the way you'd want it to:
<?php
$x = 'Подмосковные вечера';
print(strlen($x)."\n"); # 37, not 19
print(substr($x,0,1)."\n"); # �, not П
print(substr($x,0,2)."\n"); # П, not По
?>
Look at the multibyte string functions if you want to manipulate non-ASCII text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With