I am looking for ways to split a string into an array, sort of str_split(), where the chunks are all of different sizes.
I could do that by looping through the string with a bunch of substr(), but that looks neither elegant nor efficient. Is there a function that accept a string and an array, like (1, 18, 32, 41, 108, 125, 137, 152, 161), and yields an array of appropriately chopped string pieces?
Explode is inappropriate because the chunks are delimited by varying numbers of white spaces.
There is nothing in PHP that will do that for you (it’s a bit specific). So as radashk just siad, you just have to write a function
Something like that. You can then use it wherever you like, so it’s clean:
If you really wanted to, you could implode it into a regular expression:
would match what you wanted.