Last active
September 7, 2016 13:22
-
-
Save friartuck6000/7b4878a1dab839980ef243d45a4ccea2 to your computer and use it in GitHub Desktop.
Convert camel case to snake case
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 | |
/** | |
* Convert camel case to snake case. | |
* | |
* DISCLAIMER: Not mine. Got it from {@link http://stackoverflow.com/a/35719689}. | |
* | |
* @param string $camelString The source string. | |
* @return string The converted string. | |
*/ | |
function camel2snake($camelString) | |
{ | |
return strtolower(preg_replace(['/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/'], '$1_$2', $camelString)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment