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.31, 8.4.9 - 8.4.22, 8.5.3 - 8.5.7

preferences:
43.74 ms | 533 KiB | 4 Q