How to explode a string on upper case characters

→ Are you a new visitor? Please visit the page guidance for new visitors ←

How to explode a string on upper case characters

Problem

You have a string with the following value “thisStringMustBeSplittedAfterUpperCase” and you want to obtain every word separately in an array, splitted after upper case.

Solution

Output

The output of the $chunks array obtained with a var_dump($chunks) will be:

Solution in a function

The above example will have the same output but will be a more modular solution in case you want to use that in more than one place.

Request an article ←