from_camel_case, to_camel_case

· 14년 전 · 617
표기법이 달라 같은 엔티티 참조가 어려울때, 한쪽의 표기법을 변경하는 방법
자바나 자바스크립트 변수명 또는 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,332
14년 전 조회 4,436
14년 전 조회 1,309
14년 전 조회 1,074
14년 전 조회 569
14년 전 조회 801
14년 전 조회 624
14년 전 조회 505
14년 전 조회 587
14년 전 조회 570
14년 전 조회 509
14년 전 조회 1,382
14년 전 조회 705
14년 전 조회 559
14년 전 조회 535
14년 전 조회 592
14년 전 조회 887
14년 전 조회 790
14년 전 조회 1,376
14년 전 조회 997
14년 전 조회 3,454
14년 전 조회 673
14년 전 조회 1,229
14년 전 조회 964
14년 전 조회 2,704
14년 전 조회 2,311
14년 전 조회 518
14년 전 조회 1,579
14년 전 조회 527
14년 전 조회 2,325
14년 전 조회 1,866
14년 전 조회 483
14년 전 조회 5,566
14년 전 조회 836
14년 전 조회 1,344
14년 전 조회 1,164
14년 전 조회 1,206
14년 전 조회 1,084
14년 전 조회 1,086
14년 전 조회 915
14년 전 조회 1,269
14년 전 조회 1,660
14년 전 조회 679
14년 전 조회 1,056
14년 전 조회 2,093
14년 전 조회 1,945
14년 전 조회 899
14년 전 조회 1,393
14년 전 조회 3,881
14년 전 조회 618
14년 전 조회 2,603
14년 전 조회 1,378
14년 전 조회 1,813
14년 전 조회 1,027
14년 전 조회 799
14년 전 조회 796
14년 전 조회 941
14년 전 조회 1,015
14년 전 조회 1,897
14년 전 조회 3,150
14년 전 조회 2,196
14년 전 조회 905
14년 전 조회 1,517
14년 전 조회 1,758
14년 전 조회 560
14년 전 조회 1,803
14년 전 조회 3,040
14년 전 조회 1,720
14년 전 조회 2,657
14년 전 조회 3,967
14년 전 조회 3,998
14년 전 조회 2,407
14년 전 조회 846
14년 전 조회 1,138
14년 전 조회 3,959
14년 전 조회 2,279
14년 전 조회 1,430
14년 전 조회 3,798
14년 전 조회 2,475
14년 전 조회 558
14년 전 조회 2,464
14년 전 조회 610
14년 전 조회 841
14년 전 조회 1,676
14년 전 조회 1,302
14년 전 조회 1,556
14년 전 조회 1,117
14년 전 조회 2,115
14년 전 조회 789
14년 전 조회 801
14년 전 조회 630
14년 전 조회 1,433
14년 전 조회 1,046
14년 전 조회 767
14년 전 조회 5,295
14년 전 조회 1,911
14년 전 조회 1,146
14년 전 조회 648
14년 전 조회 9,440
14년 전 조회 1,556
🐛 버그신고