Note: I recently asked this question but it turns out the solution I'm looking for is more advanced than I initially thought.
Using preg_split, how would I split this up, note that the string before the delimiters varies:
$string = "big red apple one purple grape some stuff then green apple yatta yatta red cherry green gape";
I want to use an array of strings as the delimiters and I want them to be included in the result. Deliminters: [apple, grape, cherry]
My desired output is:
Array("big red apple", "one purple grape", "some stuff then green apple", "yatta yatta red cherry", "green grape");
Here's what I had originally:
$string = "big red apple one purple grape some stuff then green apple yatta yatta red cherry green gape";
$matches = preg_split('(apple|grape|cherry)', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
print_r($matches);
It prints this: Array ( [0] => big red [1] => one purple [2] => some stuff then green [3] => yatta yatta red [4] => green gape )
without the delimiters.