I am looking to breakdown a paragraph into sentences and then into 'exploded' strings but need to keep the punctuations as elements of the array.
Example text:
$meta = 'I am looking to break this paragraph into chunks.
I have researched, tried and tested various combinations; however, I cannot
seem to make it work. Would anyone help me figure this out?
I thank you in advance...'
The desired output would be:
Array ( [0] =>
Array ( [0] => I [1] => am [2] => looking [3] => to [4] => break [5] => [6] => this [7] => paragraph [8] => into [9] => chunks [10] => . )
[1] =>
Array ( [0] => I [2] => have [3] => researched [4] => , [5] => tried [......
......] [5] => figure [6] => this [7] => out [8] => ? )
[3] =>
Array ( [0] => I [1] => thank [2] => you [3] => in [4] => advance [5] => ... )
)
I have tried using:
$s = preg_split('/\s*[!?.]\s*/u', $meta, -1, PREG_SPLIT_NO_EMPTY);
to separate out the sentences but whilst this works, the punctuation disappears.
I would really appreciate help with building this two level array with the punctuation