from_camel_case, to_camel_case

· 14년 전 · 1757
표기법이 달라 같은 엔티티 참조가 어려울때, 한쪽의 표기법을 변경하는 방법
자바나 자바스크립트 변수명 또는 XML의 node, attribute name이 camel 을 쓰고,
DB Column이 underscore(_) 를 쓰죠.
( db 컬럼과 xml 의 node명을 상호 참조할경우 아래와 같이 변환해서 쓰면 좋습니다.
xml을 파싱해서 db에 넣는다던지, db를 조회해서 xml을 만든다던지..
)
 
 
<?php
  /**
   * Translates a camel case string into a string with underscores (e.g. firstName -> first_name)
   * @param    string   $str    String in camel case format
   * @return    string            $str Translated into underscore format
   */
  function from_camel_case($str) {
    $str[0] = strtolower($str[0]);
    $func = create_function('$c', 'return "_" . strtolower($c[1]);');
    return preg_replace_callback('/([A-Z])/', $func, $str);
  }
 
  /**
   * Translates a string with underscores into camel case (e.g. first_name -> firstName)
   * @param    string   $str                     String in underscore format
   * @param    bool     $capitalise_first_char   If true, capitalise the first char in $str
   * @return   string                              $str translated into camel caps
   */
  function to_camel_case($str, $capitalise_first_char = false) {
    if($capitalise_first_char) {
      $str[0] = strtoupper($str[0]);
    }
    $func = create_function('$c', 'return strtoupper($c[1]);');
    return preg_replace_callback('/_([a-z])/', $func, $str);
  }

$test1 =   "MODIFY_DATE";
$test2 =   "modifyDate";
$result1 = to_camel_case(strtolower($test1));
$result2 = strtoupper(from_camel_case($test2));
echo "$test1 => $result1 <br>";
echo "$test2 => $result2 <br>";
?>
output:
MODIFY_DATE => modifyDate
modifyDate => MODIFY_DATE
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
14년 전 조회 2,413
14년 전 조회 5,526
14년 전 조회 2,407
14년 전 조회 2,164
14년 전 조회 1,660
14년 전 조회 1,889
14년 전 조회 1,725
14년 전 조회 1,583
14년 전 조회 1,678
14년 전 조회 1,655
14년 전 조회 1,617
14년 전 조회 2,462
14년 전 조회 1,800
14년 전 조회 1,687
14년 전 조회 1,595
14년 전 조회 1,658
14년 전 조회 1,979
14년 전 조회 1,887
14년 전 조회 2,498
14년 전 조회 2,089
14년 전 조회 4,574
14년 전 조회 1,804
14년 전 조회 2,349
14년 전 조회 2,070
14년 전 조회 3,803
14년 전 조회 3,439
14년 전 조회 1,603
14년 전 조회 2,671
14년 전 조회 1,643
14년 전 조회 3,463
14년 전 조회 2,993
14년 전 조회 1,605
14년 전 조회 6,704
14년 전 조회 1,966
14년 전 조회 2,506
14년 전 조회 2,296
14년 전 조회 2,127
14년 전 조회 2,200
14년 전 조회 2,209
14년 전 조회 2,078
14년 전 조회 2,388
14년 전 조회 2,785
14년 전 조회 1,817
14년 전 조회 2,198
14년 전 조회 3,218
14년 전 조회 3,097
14년 전 조회 2,059
14년 전 조회 2,532
14년 전 조회 5,027
14년 전 조회 1,758
14년 전 조회 3,740
14년 전 조회 2,475
14년 전 조회 2,949
14년 전 조회 2,147
14년 전 조회 1,913
14년 전 조회 1,932
14년 전 조회 2,075
14년 전 조회 2,143
14년 전 조회 3,048
14년 전 조회 4,263
14년 전 조회 3,338
14년 전 조회 2,047
14년 전 조회 2,633
14년 전 조회 2,892
14년 전 조회 1,700
14년 전 조회 2,943
14년 전 조회 4,181
14년 전 조회 2,850
14년 전 조회 3,765
14년 전 조회 4,916
14년 전 조회 5,148
14년 전 조회 3,521
14년 전 조회 1,945
14년 전 조회 2,285
14년 전 조회 5,072
14년 전 조회 3,380
14년 전 조회 2,530
14년 전 조회 4,927
14년 전 조회 3,570
14년 전 조회 1,672
14년 전 조회 3,581
14년 전 조회 1,699
14년 전 조회 1,968
14년 전 조회 2,822
14년 전 조회 2,458
14년 전 조회 2,687
14년 전 조회 2,223
14년 전 조회 3,229
14년 전 조회 1,899
14년 전 조회 1,932
14년 전 조회 1,742
14년 전 조회 2,520
14년 전 조회 2,164
14년 전 조회 1,870
14년 전 조회 6,411
14년 전 조회 3,017
14년 전 조회 2,275
14년 전 조회 1,769
14년 전 조회 1.1만
14년 전 조회 2,669