Skip to content

Instantly share code, notes, and snippets.

@friartuck6000
Last active September 7, 2016 13:22
Show Gist options
  • Save friartuck6000/7b4878a1dab839980ef243d45a4ccea2 to your computer and use it in GitHub Desktop.
Save friartuck6000/7b4878a1dab839980ef243d45a4ccea2 to your computer and use it in GitHub Desktop.
Convert camel case to snake case
<?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