I have a line: CamelCaseString
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?
You must use regular expressions. Try the following: preg_match_all('/[AZ][^AZ]*/', "CamelCaseString", $results);
preg_match_all('/[AZ][^AZ]*/', "CamelCaseString", $results);
An array containing all the words will be stored in $ results [0].
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"
The split () function is deprecated, so I would be looking for a solution that uses some other function.