3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test_str = "I&#039;ll"; function setup_functions(){ global $smcFunc; $smcFunc = array(); $utf8=1; $ent_list = '&(#\d{1,7}|quot|amp|lt|gt|nbsp);'; $ent_check = array('preg_replace(\'~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~e\', \'$smcFunc[\\\'entity_fix\\\'](\\\'\\2\\\')\', ', ')'); $smcFunc += array( 'entity_fix' => create_function('$string', ' $num = substr($string, 0, 1) === \'x\' ? hexdec(substr($string, 1)) : (int) $string; return $num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202E || $num === 0x202D ? \'\' : \'&#\' . $num . \';\';'), 'strlen' => create_function('$string', ' global $smcFunc; return strlen(preg_replace(\'~' . $ent_list . '|.~u' . '\', \'_\', ' . implode('$string', $ent_check) . '));') ); } setup_functions(); echo "Length = " . $smcFunc['strlen']($test_str) . "\n"; ?>

preferences:
38.8 ms | 404 KiB | 5 Q