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.2.18, 8.3.5 - 8.3.6
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:
179.38 ms | 403 KiB | 162 Q