PHP substring and strange icon on rendered html

php, string, substring

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.

Problem

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?

Original source