Last active
September 6, 2022 09:32
-
-
Save arobinski/27419c8f309d74a8d0cb to your computer and use it in GitHub Desktop.
Change CamelCaseString to underscore_style_string
This file contains hidden or 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
/** | |
* Changes a CamelCaseString into a string_with_underscores. | |
* | |
* @param string $string CamelCase string | |
* @return string string_with_underscores | |
*/ | |
public static function camelCaseToUnderscoreStyle($string) | |
{ | |
return preg_replace_callback( | |
'|[A-Z]|', | |
function ($match) { | |
return '_' . strtolower($match[0]); | |
}, | |
lcfirst($string) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Taking into account unicode support.
http://phpfiddle.org/main/code/sy15-vtqp