PHP Velho Oeste 2024

명령 구분

C나 펄처럼, PHP는 각 명령 구문 끝을 세미콜론으로 종료해야 합니다. PHP 코드 블록을 종료하면 자동으로 세미콜론을 적용합니다; PHP 블록의 마지막 줄에는 세미콜론 종료를 하지 않아도 됩니다. 블록의 닫기 태그는 바로 뒤에 따라올 수 있는 줄바꿈도 포함합니다.

<?php
    
echo 'This is a test';
?>

<?php echo 'This is a test' ?>

<?php echo '마지막 닫기 태그를 생략합니다';

Note:

파일의 마지막에서 PHP 블록의 닫기 태그를 생략할 수 있으며, 때로는 유용합니다. includerequire를 사용할 경우, 원하지 않은 공백이 파일 마지막에 들어가지 않게 함으로써, 나중에 추가 응답 헤더를 추가할 수 있습니다. 또한 출력 버퍼링을 사용할 경우에도 포함한 파일들에 의해서 각 파트의 마지막에 원하지 않은 공백을 피할 수 있으므로 도움이 됩니다.

add a note add a note

User Contributed Notes 2 notes

up
69
Krishna Srikanth
17 years ago
Do not mis interpret

<?php echo 'Ending tag excluded';

with

<?php echo 'Ending tag excluded';
<
p>But html is still visible</p>

The second one would give error. Exclude ?> if you no more html to write after the code.
up
12
M1001
1 year ago
You are also able to write more than one statement in one line, just separating with a semicolon, example:

<?php
echo "a"; echo "b"; echo "c";
#The output will be "abc" with no errors
?>
To Top