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.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.16, 8.3.0 - 8.3.3
array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先秦兩漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', )
Output for 7.3.0 - 7.3.33
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 => '漢', )

preferences:
123.01 ms | 402 KiB | 156 Q