"PHP 문자열 nowdoc"의 두 판 사이의 차이

3번째 줄: 3번째 줄:
;PHP 나우닥
;PHP 나우닥
*[[PHP heredoc]]과 비슷하지만 <code>$변수명</code>이 그대로 출력됨
*[[PHP heredoc]]과 비슷하지만 <code>$변수명</code>이 그대로 출력됨
*<code><<<</code> 다음 식별자를 작은따옴표 <code>'</code>로 묶어줌


==예제 1: 기본==
==예제 1: 기본==

2016년 3월 5일 (토) 18:16 판

1 개요

PHP nowdoc
PHP 나우닥
  • PHP heredoc과 비슷하지만 $변수명이 그대로 출력됨
  • <<< 다음 식별자를 작은따옴표 '로 묶어줌

2 예제 1: 기본

<?php
$str = <<<'EOT'
안녕
친구들
EOT;
echo "str=[$str]\n";
[root@zetawiki ~]# php nowdoc.php
str=[안녕
친구들]

3 예제 2: 파라미터로 사용

<?php
$str = <<<'EOT'
안녕
친구들
EOT;
echo "str=[$str]\n";
[root@zetawiki ~]# php nowdoc2.php
str=[HELLO,
WORLD!]

4 예제 3: 변수명 그대로 ★

  • PHP heredoc과는 달리, 역슬래시 없어도 변수명이 그대로 출력됨
<?php
$greeting = 'Good Morning';
$str = <<<'EOT'
Hello,
$greeting
EOT;
echo "str=[$str]\n";
[root@zetawiki ~]# php nowdoc3.php
str=[Hello,
$greeting]

5 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}