3v4l.org

run code in 500+ 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 8.6.0
array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- Deprecated: Function mb_split() is deprecated since 8.6, because the underlying library is no longer maintained in /in/lEeLG on line 9 array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', )
Output for 8.3.5 - 8.3.37, 8.4.1 - 8.4.28, 8.5.0 - 8.5.13, 8.2.18 - 8.2.36, 8.1.28 - 8.1.34, 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 => '漢', )
Output for 8.3.0 - 8.3.4, 8.2.0 - 8.2.17, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34
array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', ) --- array ( 0 => '先秦兩漢', ) --- array ( 0 => '先', 1 => '秦', 2 => '兩', 3 => '漢', )

preferences:
16.34 ms | 1191 KiB | 6 Q