3v4l.org

run code in 300+ PHP versions simultaneously
<?php // n-dashes are encoded as byte sequence \xe2\x80\x93 in UTF-8 $str = 'foo–bar–baz'; // take substring of 4 bytes length starting with the 4th byte var_dump(mb_strcut($str, 4, 4, 'UTF-8')); // take substring of 4 code points length starting with the 4th code point var_dump(mb_substr($str, 4, 4, 'UTF-8'));

preferences:
51.41 ms | 402 KiB | 5 Q