3v4l.org

run code in 300+ PHP versions simultaneously
<?php if ( !function_exists( 'mb_convert_encoding' ) ) { exit('[mbstring not loaded]'); } $oldSub = mb_substitute_character(); mb_substitute_character( 0xfffd ); $res = mb_convert_encoding( "\xf4\x90\x80\x80 \xc2", 'UTF-8', 'UTF-8' ); mb_substitute_character( $oldSub ); if ( $res === "\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd \xef\xbf\xbd" ) { // mbstring follows best practices. $level = 3; } elseif ( $res[0] !== "\xef" ) { // mbstring is old; it treats values above U+10FFFF as valid. // This is the case for PHP 5.3. $level = 0; } elseif ( substr_compare( $res, " \xef\xbf\xbd", -4 ) !== 0 ) { // mbstring is affected by <https://bugs.php.net/bug.php?id=65045>. $level = 1; } else { // mbstring nevertheless doesn't follow best practices. (Perhaps this system // has an old version of ICU, and mbstring was changed to use it.) $level = 2; } echo $level;

preferences:
38.38 ms | 402 KiB | 5 Q