Skip to content
Advertisement

Explode a string on upper case characters?

Ho can i explode $param string into $chunks pieces based on upper-case characters?

JavaScript

Advertisement

Answer

Using preg_split() on [A-Z] should do:

JavaScript

EDIT
If you don’t need the array itself, you can just preprend uppercase characters (except the first) with a hyphen (-):

JavaScript

(demo)

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement