What are the potential pitfalls of using preg_split or explode functions for parsing strings in PHP?

Using preg_split or explode functions for parsing strings in PHP can lead to potential pitfalls such as not handling multiple delimiters, not accounting for whitespace, or not capturing the delimiters themselves. To solve these issues, consider using preg_match_all with a regex pattern that captures both the delimiters and the substrings between them.

$string = "apple,orange;banana grape";
$pattern = '/(\w+)/';
preg_match_all($pattern, $string, $matches);
print_r($matches[0]);