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.2.32, 8.3.5 - 8.3.33, 8.4.9 - 8.4.24, 8.5.3 - 8.5.9

preferences:
47.81 ms | 561 KiB | 4 Q