3v4l.org

run code in 500+ PHP versions simultaneously
<?php $sentence = 'hypertext language, programming'; $keywords = preg_split('/[\s,]+/', $sentence); // ['hypertext', 'language', 'programming'] $separators = preg_split('/([\s,]+)/', $sentence, flags: PREG_SPLIT_DELIM_CAPTURE); // ['hypertext', ' ', 'language', ', ', 'programming'] $separator2s = preg_split('/([\s,])([\s]*)/', $sentence, flags: PREG_SPLIT_DELIM_CAPTURE); // ['hypertext', ' ', '', 'language', ',', ' ', 'programming'] $words = explode(' ', $sentence); // ['hypertext', 'language,', 'programming'] // comma is still collected ?>
Output for 8.2.31, 8.3.5 - 8.3.32, 8.4.9 - 8.4.23, 8.5.3 - 8.5.8

preferences:
50.2 ms | 545 KiB | 4 Q