I have different strings that are function names like
createWebsiteManagementUsers
I want to change them into
Create Website Mangement Users
How can i achieve that in PHP?
I have different strings that are function names like
createWebsiteManagementUsers
I want to change them into
Create Website Mangement Users
How can i achieve that in PHP?
You can use ucwords():-
echo ucwords($string);
Output:- https://3v4l.org/sCiEJ
Note:- In your expected outcome spaces comes? Do you want that too?
If Yes then use:-
echo ucwords(implode(' ',preg_split('/(?=[A-Z])/', 'createWebsiteManagementUsers')));
Example with Output:- https://3v4l.org/v3KUK
Use below code to solve:
$String = 'createWebsiteManagementUsers';
$Words = preg_replace('/(?<!\ )[A-Z]/', ' $0', $String);
echo ucwords($Words);
//output will be Create Website Mangement Users
try this
$data = preg_split('/(?=[A-Z])/', 'createWebsiteManagementUsers');
$string = implode(' ', $data);
echo ucwords($string);
output will be
Create Website Management Users
Here is what you need. This has the spaces as well!
function parseCamelCase($camelCaseString){
$words_splited = preg_split('/(?=[A-Z])/',$camelCaseString);
$words_capitalized = array_map("ucfirst", $words_splited);
return implode(" ", $words_capitalized);
}
Thanks
function camelCaseToString($string)
{
$pieces = preg_split('/(?=[A-Z])/',$string);
$word = implode(" ", $pieces);
return ucwords($word);
}
$name = "createWebsiteManagementUsers";
echo camelCaseToString($name);
May be you can try something like this
//Split words with Capital letters
$pieces = preg_split('/(?=[A-Z])/', 'createWebsiteManagementUsers');
$string = implode(' ', $pieces);
echo ucwords($string);
//You will get your desire output Create Website Management Users