PHP and utf-8

Have a nice read first.


$haystack = 'Iñtërnâtiônàlizætiøn';
$needle = 'ô';
$pos = strpos($haystack, $needle);
print "Position in bytes is $pos<br>";
$substr = substr($haystack, 0, $pos);
print "Substr: $substr";

Position in bytes is 12
Substr: Iñtërnâti

$haystack = 'Iñtërnâtiônàlizætiøn';
$substr = substr($haystack, 0, 13);
print "Substr: $substr";

Substr: IñtërnâtiÃ


Now without fluffy characters

$haystack = 'Internationalization';
$needle = 'o';
$pos = strpos($haystack, $needle);
print "Position in bytes is $pos<br>";
$substr = substr($haystack, 0, $pos);
print "Substr: $substr";

Position in bytes is 9
Substr: Internati

$haystack = 'Internationalization';
$substr = substr($haystack, 0, 13);
print "Substr: $substr";

Substr: International


Damn! ;o)