Skip to content

Instantly share code, notes, and snippets.

@troelskn
Created December 22, 2010 13:45
Show Gist options
  • Select an option

  • Save troelskn/751517 to your computer and use it in GitHub Desktop.

Select an option

Save troelskn/751517 to your computer and use it in GitHub Desktop.

Revisions

  1. troelskn renamed this gist Dec 22, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. troelskn created this gist Dec 22, 2010.
    27 changes: 27 additions & 0 deletions camelize/underscore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    <?php

    /**
    * Transforms an under_scored_string to a camelCasedOne
    */
    function camelize($scored) {
    return lcfirst(
    implode(
    '',
    array_map(
    'ucfirst',
    array_map(
    'strtolower',
    explode(
    '_', $scored)))));
    }

    /**
    * Transforms a camelCasedString to an under_scored_one
    */
    function underscore($cameled) {
    return implode(
    '_',
    array_map(
    'strtolower',
    preg_split('/([A-Z]{1}[^A-Z]*)/', $cameled, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY)));
    }