from_camel_case, to_camel_case

· 14년 전 · 727
표기법이 달라 같은 엔티티 참조가 어려울때, 한쪽의 표기법을 변경하는 방법
자바나 자바스크립트 변수명 또는 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,462
14년 전 조회 4,550
14년 전 조회 1,426
14년 전 조회 1,193
14년 전 조회 709
14년 전 조회 937
14년 전 조회 745
14년 전 조회 624
14년 전 조회 699
14년 전 조회 694
14년 전 조회 641
14년 전 조회 1,517
14년 전 조회 821
14년 전 조회 688
14년 전 조회 641
14년 전 조회 709
14년 전 조회 1,001
14년 전 조회 905
14년 전 조회 1,495
14년 전 조회 1,112
14년 전 조회 3,578
14년 전 조회 798
14년 전 조회 1,351
14년 전 조회 1,096
14년 전 조회 2,832
14년 전 조회 2,440
14년 전 조회 643
14년 전 조회 1,683
14년 전 조회 664
14년 전 조회 2,453
14년 전 조회 2,001
14년 전 조회 607
14년 전 조회 5,703
14년 전 조회 959
14년 전 조회 1,475
14년 전 조회 1,292
14년 전 조회 1,322
14년 전 조회 1,214
14년 전 조회 1,213
14년 전 조회 1,033
14년 전 조회 1,392
14년 전 조회 1,785
14년 전 조회 797
14년 전 조회 1,183
14년 전 조회 2,214
14년 전 조회 2,061
14년 전 조회 1,028
14년 전 조회 1,504
14년 전 조회 4,014
14년 전 조회 728
14년 전 조회 2,724
14년 전 조회 1,488
14년 전 조회 1,940
14년 전 조회 1,152
14년 전 조회 913
14년 전 조회 928
14년 전 조회 1,067
14년 전 조회 1,149
14년 전 조회 2,027
14년 전 조회 3,268
14년 전 조회 2,313
14년 전 조회 1,026
14년 전 조회 1,628
14년 전 조회 1,893
14년 전 조회 680
14년 전 조회 1,921
14년 전 조회 3,157
14년 전 조회 1,835
14년 전 조회 2,765
14년 전 조회 4,075
14년 전 조회 4,121
14년 전 조회 2,526
14년 전 조회 949
14년 전 조회 1,256
14년 전 조회 4,080
14년 전 조회 2,397
14년 전 조회 1,547
14년 전 조회 3,922
14년 전 조회 2,592
14년 전 조회 669
14년 전 조회 2,587
14년 전 조회 716
14년 전 조회 956
14년 전 조회 1,802
14년 전 조회 1,421
14년 전 조회 1,671
14년 전 조회 1,235
14년 전 조회 2,243
14년 전 조회 900
14년 전 조회 916
14년 전 조회 745
14년 전 조회 1,551
14년 전 조회 1,177
14년 전 조회 892
14년 전 조회 5,415
14년 전 조회 2,019
14년 전 조회 1,267
14년 전 조회 748
14년 전 조회 9,547
14년 전 조회 1,672