Created
March 28, 2021 17:58
-
-
Save zanbaldwin/88c7308cfbf7727415388cf39b2498f5 to your computer and use it in GitHub Desktop.
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 | |
function camelCaseToSnakeCase(string $input): string { | |
preg_match_all('!(^[a-z\d]+)|(?:_?)([a-z\d]+|[A-Z][a-z\d]+|[A-Z][A-Z\d]*(?=_|$|[A-Z][a-z\d]))!', $input, $matches); | |
return strtolower(implode('_', array_map(function (string $part): string { | |
return trim($part, '_'); | |
}, $matches[0]))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment