如何骆驼转换为大写的英文单词在PHP

问题描述:

我有不同的字符串,就像如何骆驼转换为大写的英文单词在PHP

createWebsiteManagementUsers 

我想将它们转换为

Create Website Mangement Users 

函数名我怎么能做到这一点在PHP ?

+0

可以代替浸渍料与空间的首都,随后的比赛,然后首字母大写 – pvg

+0

http://*.com/questions/4519739/split-camelcase-word-into -word-with-php-preg-match-regular-expression – JapanGuy

+0

preg_replace('/(?

您可以使用ucwords(): -

echo ucwords($string); 

输出: - https://eval.in/750347

注: - 在您的预期结果空间来?你也想要吗?

如果是再使用: -

preg_split('/(?=[A-Z])/', $string) // split with capital letter

例与输出: - https://eval.in/750360

+0

而空格? –

+0

是的,我也想每个单词中的空格 –

+0

谢谢你这么多 –

试试这个

$data = preg_split('/(?=[A-Z])/', 'createWebsiteManagementUsers'); 

$string = implode(' ', $data); 

echo ucwords($string); 

输出将是

创建网站管理用户

+0

我也需要两者之间的空格。 –

可能是你可以尝试这样的事情

//Split words with Capital letters 
$pieces = preg_split('/(?=[A-Z])/', 'createWebsiteManagementUsers'); 

$string = implode(' ', $pieces); 

echo ucwords($string); 

//你会得到你的愿望输出创建网站管理用户

下面的代码使用解决:

$String = 'createWebsiteManagementUsers'; 
$Words = preg_replace('/(?<!\)[A-Z]/', ' $0', $String); 
echo ucwords($Words); 

//output will be Create Website Mangement Users 

试试这个:

preg_match_all('/((?:^|[A-Z])[a-z]+)/',$str,$matches); 

这是你需要的。这也有空间!

function parseCamelCase($camelCaseString){ 
    $words_splited = preg_split('/(?=[A-Z])/',$camelCaseString); 
    $words_capitalized = array_map("ucfirst", $words_splited); 
    return implode(" ", $words_capitalized); 
} 

感谢

+0

别担心,我会跟进承诺:) –

function camelCaseToString($string) 
{ 
    $pieces = preg_split('/(?=[A-Z])/',$string); 
    $word = implode(" ", $pieces); 
    return ucwords($word); 
} 

$name = "createWebsiteManagementUsers"; 
echo camelCaseToString($name);