3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function seems_utf8($str) { $length = strlen($str); for ($i = 0; $i < $length; $i++) { $c = ord($str[$i]); if ($c < 0x80) $n = 0; elseif (($c & 0xE0) == 0xC0) $n = 1; elseif (($c & 0xF0) == 0xE0) $n = 2; elseif (($c & 0xF8) == 0xF0) $n = 3; elseif (($c & 0xFC) == 0xF8) $n = 4; elseif (($c & 0xFE) == 0xFC) $n = 5; else return false; for ($j=0; $j<$n; $j++) { if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) return false; } } return true; } var_dump( seems_utf8("aťsd") );
based on euTMN
Output for 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.30 - 7.3.0beta1
bool(true)