Skip to content

Instantly share code, notes, and snippets.

@fajarwz
Created July 14, 2022 15:07
Show Gist options
  • Save fajarwz/d94cc2f72d6084525cd18bdc737a14e6 to your computer and use it in GitHub Desktop.
Save fajarwz/d94cc2f72d6084525cd18bdc737a14e6 to your computer and use it in GitHub Desktop.
Solution for a "Convert words to PascalCase" challenge
<?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