I'm trying to divide a string into two columns with 6 lines in each. The problem is that if the last line contains (Ø,Æ,Å) it will jump into the next column even though there is a space in the first.
It seems like this is a problem with encoding, anyone got a clue what might be going on? The code I am using to generate the columns is:
$iter = 6;
$str = $shortd;
$count_line = 0;
$str = $shortd;
for ($x=0; $x<$iter;){
$pos = strpos($str,"<br />");
$text = mb_substr ($str, 0, $pos + 6);
$str = mb_substr ($str, $pos + 6);
echo $text;
$x++;
}
?>
</td>
<td>
<?
for ($x=$iter; $x<$iter + $iter;){
$pos = strpos($str,"<br />");
$text = mb_substr ($str, 0, $pos + 6);
$str = mb_substr ($str, $pos + 6);
echo $text;
$x++;
}
?>
</td>
The strpos() function is not multi-byte aware. You should use mb_strpos() instead. Otherwise, you are mixing bytes and characters when dealing with positions.