from_camel_case, to_camel_case

· 14년 전 · 634
표기법이 달라 같은 엔티티 참조가 어려울때, 한쪽의 표기법을 변경하는 방법
자바나 자바스크립트 변수명 또는 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년 전 조회 1,356
14년 전 조회 4,458
14년 전 조회 1,329
14년 전 조회 1,100
14년 전 조회 593
14년 전 조회 822
14년 전 조회 637
14년 전 조회 528
14년 전 조회 608
14년 전 조회 587
14년 전 조회 524
14년 전 조회 1,403
14년 전 조회 730
14년 전 조회 582
14년 전 조회 556
14년 전 조회 606
14년 전 조회 909
14년 전 조회 807
14년 전 조회 1,401
14년 전 조회 1,023
14년 전 조회 3,473
14년 전 조회 702
14년 전 조회 1,261
14년 전 조회 986
14년 전 조회 2,729
14년 전 조회 2,329
14년 전 조회 538
14년 전 조회 1,595
14년 전 조회 541
14년 전 조회 2,346
14년 전 조회 1,892
14년 전 조회 504
14년 전 조회 5,592
14년 전 조회 854
14년 전 조회 1,360
14년 전 조회 1,181
14년 전 조회 1,221
14년 전 조회 1,103
14년 전 조회 1,104
14년 전 조회 936
14년 전 조회 1,286
14년 전 조회 1,682
14년 전 조회 701
14년 전 조회 1,073
14년 전 조회 2,109
14년 전 조회 1,962
14년 전 조회 917
14년 전 조회 1,412
14년 전 조회 3,902
14년 전 조회 635
14년 전 조회 2,620
14년 전 조회 1,388
14년 전 조회 1,829
14년 전 조회 1,041
14년 전 조회 816
14년 전 조회 816
14년 전 조회 957
14년 전 조회 1,033
14년 전 조회 1,921
14년 전 조회 3,166
14년 전 조회 2,213
14년 전 조회 928
14년 전 조회 1,535
14년 전 조회 1,780
14년 전 조회 583
14년 전 조회 1,820
14년 전 조회 3,055
14년 전 조회 1,736
14년 전 조회 2,672
14년 전 조회 3,980
14년 전 조회 4,013
14년 전 조회 2,428
14년 전 조회 864
14년 전 조회 1,162
14년 전 조회 3,977
14년 전 조회 2,299
14년 전 조회 1,439
14년 전 조회 3,817
14년 전 조회 2,494
14년 전 조회 582
14년 전 조회 2,481
14년 전 조회 629
14년 전 조회 857
14년 전 조회 1,694
14년 전 조회 1,318
14년 전 조회 1,579
14년 전 조회 1,132
14년 전 조회 2,134
14년 전 조회 807
14년 전 조회 815
14년 전 조회 653
14년 전 조회 1,450
14년 전 조회 1,063
14년 전 조회 783
14년 전 조회 5,313
14년 전 조회 1,936
14년 전 조회 1,160
14년 전 조회 661
14년 전 조회 9,460
14년 전 조회 1,572
🐛 버그신고