'Strange result in loop when use special chars
I have strange problem when special chars in loop when add br and use specal chars, if don´t use words with special chars no have problems but when use special chars and use br for show one under other show strange chars
For example if don´t use br :
$text="ála";
for($d=0;$d<strlen($text);$d++)
{
echo $text[$d];
    
}
Result: ála
If use br show strange chars
$text="ála";
for($d=0;$d<strlen($text);$d++)
{
echo $text[$d];
print "<br>";
    
}
Result : � � l a
I don´t know how fix it´s and don´t underetand why happend this issue, howewer here can explain what happend, regards
Solution 1:[1]
This is happening because an accented e is part of UTF-8, which are considered "multi-byte" characters. It outputs incorrectly because you're actually splitting the character down the middle and putting <br> in-between. Because you are splitting on the bytes of the string, and not the characters, the computer does not understand that there is an accented e anymore.
If you are using PHP 7.4, you can use the mb_str_split function instead. You need to have the mbstring extension enabled.
If you don't have that enabled, this answer can help you do it without: What is the best way to split a string into an array of Unicode characters in PHP?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | Jacob Mulquin | 
