from_camel_case, to_camel_case

· 14년 전 · 621
표기법이 달라 같은 엔티티 참조가 어려울때, 한쪽의 표기법을 변경하는 방법
자바나 자바스크립트 변수명 또는 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,338
14년 전 조회 4,441
14년 전 조회 1,318
14년 전 조회 1,081
14년 전 조회 576
14년 전 조회 806
14년 전 조회 631
14년 전 조회 515
14년 전 조회 592
14년 전 조회 575
14년 전 조회 511
14년 전 조회 1,389
14년 전 조회 711
14년 전 조회 570
14년 전 조회 541
14년 전 조회 598
14년 전 조회 890
14년 전 조회 796
14년 전 조회 1,384
14년 전 조회 1,008
14년 전 조회 3,465
14년 전 조회 683
14년 전 조회 1,234
14년 전 조회 972
14년 전 조회 2,710
14년 전 조회 2,317
14년 전 조회 524
14년 전 조회 1,583
14년 전 조회 530
14년 전 조회 2,334
14년 전 조회 1,877
14년 전 조회 488
14년 전 조회 5,573
14년 전 조회 842
14년 전 조회 1,352
14년 전 조회 1,170
14년 전 조회 1,210
14년 전 조회 1,091
14년 전 조회 1,093
14년 전 조회 922
14년 전 조회 1,274
14년 전 조회 1,669
14년 전 조회 688
14년 전 조회 1,060
14년 전 조회 2,098
14년 전 조회 1,948
14년 전 조회 907
14년 전 조회 1,399
14년 전 조회 3,886
14년 전 조회 622
14년 전 조회 2,608
14년 전 조회 1,379
14년 전 조회 1,819
14년 전 조회 1,030
14년 전 조회 805
14년 전 조회 805
14년 전 조회 949
14년 전 조회 1,020
14년 전 조회 1,907
14년 전 조회 3,155
14년 전 조회 2,201
14년 전 조회 913
14년 전 조회 1,521
14년 전 조회 1,769
14년 전 조회 567
14년 전 조회 1,805
14년 전 조회 3,042
14년 전 조회 1,727
14년 전 조회 2,663
14년 전 조회 3,972
14년 전 조회 4,001
14년 전 조회 2,415
14년 전 조회 853
14년 전 조회 1,143
14년 전 조회 3,963
14년 전 조회 2,287
14년 전 조회 1,433
14년 전 조회 3,803
14년 전 조회 2,479
14년 전 조회 568
14년 전 조회 2,467
14년 전 조회 617
14년 전 조회 848
14년 전 조회 1,684
14년 전 조회 1,306
14년 전 조회 1,566
14년 전 조회 1,124
14년 전 조회 2,122
14년 전 조회 796
14년 전 조회 804
14년 전 조회 639
14년 전 조회 1,438
14년 전 조회 1,052
14년 전 조회 772
14년 전 조회 5,298
14년 전 조회 1,921
14년 전 조회 1,151
14년 전 조회 649
14년 전 조회 9,447
14년 전 조회 1,562
🐛 버그신고