Last active
September 11, 2015 12:58
-
-
Save shengjie/8c264449e020481d442b to your computer and use it in GitHub Desktop.
Simple helper function to convert camelCase <=> snakeCase
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
<?php | |
class StringCaseUtils | |
{ | |
public static function toSnakeCase($camelCase) | |
{ | |
return strtolower(preg_replace('/([A-Z])/', '_$1', lcfirst($camelCase))); | |
} | |
public static function toCamelCase($snakeCase) | |
{ | |
return implode('', array_map('ucfirst', explode("_", $snakeCase))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment