Created
March 28, 2010 00:09
-
-
Save 13k/346446 to your computer and use it in GitHub Desktop.
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 | |
| /*** | |
| * Helper functions to convert strings: | |
| * - from CamelCase to camel_case and; | |
| * - from under_score to UnderScore | |
| * | |
| * These are very probably not fast (or the fastest version). | |
| ***/ | |
| function camelize($str) | |
| { | |
| return implode('', explode(' ', ucwords(implode(' ', explode('_', $str))))); | |
| } | |
| function underline($str) | |
| { | |
| $words = array(); | |
| $split = preg_split('/([A-Z])/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); | |
| for ($i = 0; $i < count($split); $i += 2) { | |
| $words[] = strtolower($split[$i] . $split[$i+1]); | |
| } | |
| return implode('_', $words); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment