function getPascalCase($input) {
if (strpos($input, ' ') === false) {
$input = preg_replace('/(?<=[a-z])(?=[A-Z])/', ' ', $input);
}
$words = explode(' ', strtolower($input));
$result = '';
foreach ($words as $word) {
if (strlen($word) > 0) {
$result .= strtoupper($word[0]) . substr($word, 1);
}
}
return str_replace('_', '', $result);
}
echo getPascalCase("get file content") . "\n";
echo getPascalCase("get_file_content") . "\n";
echo getPascalCase("get______file___content") . "\n";
echo getPascalCase("get______file____ content") . "\n";
echo getPascalCase("GET FILE CONTENT") . "\n";
echo getPascalCase("get file content") . "\n";
echo getPascalCase("getFileContent") . "\n";
/*
run:
GetFileContent
Getfilecontent
Getfilecontent
GetfileContent
GetFileContent
GetFileContent
GetFileContent
*/