How to break a string in capital letters using PHP?

I have a line: CamelCaseString

I want to explode (), split () or some better capitalization method to break this string into separate words.

What is the easiest way to do this?

--- UPDATE DECISION ---

This link refers to a slightly different question, but I think that the answer, as a rule, will be more useful than the answers to the current question on this page: How to add a space to the line in capital letters, but save continuous capital with PHP and Regex?

+4
source share
3 answers

You must use regular expressions. Try the following: preg_match_all('/[AZ][^AZ]*/', "CamelCaseString", $results);

An array containing all the words will be stored in $ results [0].

+14
source

This also works.

 $split = preg_split("/(?<=[az])(?![az])/", "CamelCaseString", -1, PREG_SPLIT_NO_EMPTY); 

And he will not break the long lines of capital letters. That is, "MySQL" will become "My" and "SQL"

+7
source

The split () function is deprecated, so I would be looking for a solution that uses some other function.

-1
source

All Articles