Hello! Instead of 'Hello World!' displays ! Tell me ...
$str = 'Привет Мир!'; for($i=0; $i<strlen($str); $i++) { echo $str[$i], ' '; }
And this is how it displays normally:
$str = 'Привет Мир!'; echo $str;
Hello! Instead of 'Hello World!' displays ! Tell me ...
$str = 'Привет Мир!'; for($i=0; $i<strlen($str); $i++) { echo $str[$i], ' '; }
And this is how it displays normally:
$str = 'Привет Мир!'; echo $str;
Use the mb_substr
function:
$str = 'Привет Мир!'; for($i=0; $i<strlen($str); $i++) { echo mb_substr($str, $i, 1, 'utf-8'), ' '; }
In more detail:
In addition to all the scams, you still need to send the headers:
header('Content-Type: text/html; charset=utf-8');
If the code is written in an empty file.
If it is UTF-8 , then strlen for Cyrillic characters will be 22 characters long (maybe 20) because the characters are encoded in 2 bytes, because we need the function mb_strlen . Try it.
Set the file encoding to utf-8 and in the root of your project or site create a .htaccess file and insert the line AddDefaultCharset utf8 into it
Source: https://ru.stackoverflow.com/questions/234849/
All Articles