3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* The Euro sign--U+20AC--followed by " hi there", in UTF-8. */ $teststr = "\xe2\x82\xac hi there"; /* Split it into individual characters, passing the /u flag to tell PCRE to interpret the string as UTF-8. */ $testchars = preg_split('//u', $teststr, -1, PREG_SPLIT_NO_EMPTY); /* Get some output that should be equivalent. */ preg_match_all('/./u', $teststr, $matches); $goodtestchars = $matches[0]; /* The arrays should be the same length. */ print "This should be 1: '".(count($testchars) == count($goodtestchars))."'\n"; /* And the octet count of the first entry should be three for both arrays. */ print 'These both should be three: '; print strlen($testchars[0]).', '.strlen($goodtestchars[0]). "\n";

preferences:
41.13 ms | 402 KiB | 5 Q