표기법이 달라 같은 엔티티 참조가 어려울때, 한쪽의 표기법을 변경하는 방법
자바나 자바스크립트 변수명 또는 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);
}
/**
* 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>";
echo "$test2 => $result2 <br>";
?>
output:
MODIFY_DATE => modifyDate
modifyDate => MODIFY_DATE
modifyDate => MODIFY_DATE
게시판 목록
팁게시판
디자인과 관련된 유용한 정보를 공유하세요.
질문은 상단의 QA에서 해주시기 바랍니다.
질문은 상단의 QA에서 해주시기 바랍니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6002 | 9년 전 | 171 | ||
| 6001 | 9년 전 | 147 | ||
| 6000 | 9년 전 | 193 | ||
| 5999 | 9년 전 | 137 | ||
| 5998 | 9년 전 | 181 | ||
| 5997 | 9년 전 | 200 | ||
| 5996 | 9년 전 | 160 | ||
| 5995 | 9년 전 | 211 | ||
| 5994 | 9년 전 | 163 | ||
| 5993 | 9년 전 | 233 | ||
| 5992 | 9년 전 | 314 | ||
| 5991 | 9년 전 | 318 | ||
| 5990 | 9년 전 | 261 | ||
| 5989 | 9년 전 | 230 | ||
| 5988 | 9년 전 | 225 | ||
| 5987 | 9년 전 | 196 | ||
| 5986 | 9년 전 | 233 | ||
| 5985 | 9년 전 | 199 | ||
| 5984 | 9년 전 | 163 | ||
| 5983 | 9년 전 | 163 | ||
| 5982 | 9년 전 | 214 | ||
| 5981 | 9년 전 | 254 | ||
| 5980 | 9년 전 | 194 | ||
| 5979 | 9년 전 | 225 | ||
| 5978 | 9년 전 | 197 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기