Skip to content

Instantly share code, notes, and snippets.

@devster
Created December 4, 2013 08:17
Show Gist options
  • Save devster/7783986 to your computer and use it in GitHub Desktop.
Save devster/7783986 to your computer and use it in GitHub Desktop.
Transform a camel case string to an underscore string
<?php
/**
* Transform a camel case string to an underscore string
*
* @param string $str
* @return string
*/
public static function camelCaseToUnderscore($str)
{
return strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $str));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment