3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string='先秦兩漢'; var_export(preg_split('~~u', $string, 0, PREG_SPLIT_NO_EMPTY)); echo "\n---\n"; var_export(preg_split('~\X\K~u', $string, 0, PREG_SPLIT_NO_EMPTY)); echo "\n---\n"; var_export(preg_split('~\X\K(?!$)~u', $string)); echo "\n---\n"; var_export(mb_split('\X\K(?!$)', $string)); echo "\n---\n"; var_export(preg_match_all('~\X~u', $string, $out) ? $out[0] : []);
Output for 7.3.0 - 7.3.33, 8.1.28 - 8.1.30, 8.2.18 - 8.2.25, 8.3.5 - 8.3.13
array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', )
Output for 7.1.25 - 7.1.28, 7.2.0 - 7.2.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先秦兩漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', )

preferences:
60.99 ms | 409 KiB | 5 Q