How can a string be effectively split into fragments based on specific criteria, such as separating days of the week from time intervals, in PHP?

To split a string into fragments based on specific criteria, such as separating days of the week from time intervals, you can use regular expressions in PHP. By defining a pattern that matches the desired criteria, you can then use the `preg_split()` function to split the string accordingly.

$string = "Monday 9:00-12:00, Tuesday 10:00-13:00, Wednesday 8:30-11:30";
$fragments = preg_split('/,?\s*(?=\b(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\b)/', $string);

foreach ($fragments as $fragment) {
    echo $fragment . "\n";
}