from_camel_case, to_camel_case

· 14년 전 · 703
표기법이 달라 같은 엔티티 참조가 어려울때, 한쪽의 표기법을 변경하는 방법
자바나 자바스크립트 변수명 또는 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,424
14년 전 조회 4,518
14년 전 조회 1,392
14년 전 조회 1,166
14년 전 조회 663
14년 전 조회 892
14년 전 조회 702
14년 전 조회 596
14년 전 조회 670
14년 전 조회 649
14년 전 조회 601
14년 전 조회 1,474
14년 전 조회 785
14년 전 조회 651
14년 전 조회 609
14년 전 조회 668
14년 전 조회 964
14년 전 조회 871
14년 전 조회 1,465
14년 전 조회 1,075
14년 전 조회 3,545
14년 전 조회 767
14년 전 조회 1,316
14년 전 조회 1,046
14년 전 조회 2,792
14년 전 조회 2,402
14년 전 조회 603
14년 전 조회 1,658
14년 전 조회 612
14년 전 조회 2,404
14년 전 조회 1,964
14년 전 조회 569
14년 전 조회 5,653
14년 전 조회 923
14년 전 조회 1,428
14년 전 조회 1,257
14년 전 조회 1,279
14년 전 조회 1,167
14년 전 조회 1,166
14년 전 조회 1,001
14년 전 조회 1,358
14년 전 조회 1,751
14년 전 조회 755
14년 전 조회 1,146
14년 전 조회 2,174
14년 전 조회 2,026
14년 전 조회 994
14년 전 조회 1,470
14년 전 조회 3,971
14년 전 조회 704
14년 전 조회 2,688
14년 전 조회 1,447
14년 전 조회 1,898
14년 전 조회 1,108
14년 전 조회 873
14년 전 조회 875
14년 전 조회 1,029
14년 전 조회 1,104
14년 전 조회 1,985
14년 전 조회 3,229
14년 전 조회 2,280
14년 전 조회 994
14년 전 조회 1,590
14년 전 조회 1,853
14년 전 조회 652
14년 전 조회 1,874
14년 전 조회 3,121
14년 전 조회 1,799
14년 전 조회 2,740
14년 전 조회 4,039
14년 전 조회 4,089
14년 전 조회 2,488
14년 전 조회 917
14년 전 조회 1,224
14년 전 조회 4,045
14년 전 조회 2,356
14년 전 조회 1,517
14년 전 조회 3,879
14년 전 조회 2,552
14년 전 조회 638
14년 전 조회 2,558
14년 전 조회 691
14년 전 조회 922
14년 전 조회 1,759
14년 전 조회 1,379
14년 전 조회 1,638
14년 전 조회 1,196
14년 전 조회 2,205
14년 전 조회 871
14년 전 조회 878
14년 전 조회 711
14년 전 조회 1,511
14년 전 조회 1,131
14년 전 조회 846
14년 전 조회 5,379
14년 전 조회 1,999
14년 전 조회 1,228
14년 전 조회 714
14년 전 조회 9,521
14년 전 조회 1,632