Created
July 14, 2022 15:07
-
-
Save fajarwz/d94cc2f72d6084525cd18bdc737a14e6 to your computer and use it in GitHub Desktop.
Solution for a "Convert words to PascalCase" challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// For example: if str is "BOB loves-coding" then your program should return the string bobLovesCoding. | |
function toPascalCase($str) { | |
$separators = [' ', '-', '%', '*']; | |
$separatorsInString = implode('', $separators); | |
return str_replace($separators, '', ucwords(strtolower($str), $separatorsInString)); | |
} | |
echo toPascalCase("BOB loves-coding%so*he IS Awesome"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment