본문 바로가기

ㅋ/PHP

php 스트링 표현에도 이렇게 다른 점이...

http://kr.php.net/manual/en/language.types.string.php

새삼 알았네...

' ' 로 묶는거랑,

" " 로 묶는거랑,

<<< 사용하는거랑, 등등등

요약하자면...

1.
' '로 묶으면 '를 제외한 소스 그대로의 표현을 그대로 적용한다
echo 'Variables \'do\' "not" $expand $either';
-> Variables 'do' "not" $expand $either

2.
" "로 묶으면 여러개의 Escaped character를 가질 수 있다.
\n : linefeed (LF or 0x0A (10) in ASCII)
\r : carriage return (CR or 0x0D (13) in ASCII)
\t : horizontal tab (HT or 0x09 (9) in ASCII)
\v : vertical tab (VT or 0x0B (11) in ASCII) (since PHP 5.2.5)
\f : form feed (FF or 0x0C (12) in ASCII) (since PHP 5.2.5)
\\ : backslash
\$ : dollar sign
\" : double-quote
\[0-7]{1,3} : the sequence of characters matching the regular expression is a character in octal notation 
\x[0-9A-Fa-f]{1,2} : the sequence of characters matching the regular expression is a character in hexadecimal notation

3. Heredoc
<<<로 시작해서 label을 붙히고, 스트링을 이어 쓸 수 있다.
label은 "label"로도 가능(5.3이후)
그 안의 스트링은 2와 같은 동작을 한다.

4. Nowdoc
<<<로 시작해서 'label'을 붙히고, 스트링을 이어 쓸 수 있다.
그 안의 스트링은 1과 같은 동작을 한다.

자세한 것은 홈페이지에서 정독을...

' > PHP' 카테고리의 다른 글

DB연동 주소찾기 다중 셀렉트  (0) 2010.11.09
php array_multisort()  (0) 2010.10.02
php foreach  (0) 2010.10.01
php include(), include_once(), require(), require_once()의 차이점  (0) 2010.09.29
php ereg/eregi/reg_replace deprecated..  (0) 2010.09.26