What are some alternative methods to explode for splitting data with irregular spacing in PHP?

When splitting data with irregular spacing in PHP, the explode function may not work effectively due to the varying spacing between elements. An alternative method is to use a regular expression with the preg_split function to split the data based on a pattern, such as multiple spaces or tabs. This allows for more flexibility in handling irregular spacing.

$data = "apple   banana orange     grape";
$split_data = preg_split('/\s+/', $data, -1, PREG_SPLIT_NO_EMPTY);
print_r($split_data);