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.
C나 펄처럼, PHP는 각 명령 구문 끝을 세미콜론으로 종료해야 합니다. PHP 코드 블록을 종료하면 자동으로 세미콜론을 적용합니다; PHP 블록의 마지막 줄에는 세미콜론 종료를 하지 않아도 됩니다. 블록의 닫기 태그는 바로 뒤에 따라올 수 있는 줄바꿈도 포함합니다.
<?php
echo 'This is a test';
?>
<?php echo 'This is a test' ?>
<?php echo '마지막 닫기 태그를 생략합니다';
Note:
파일의 마지막에서 PHP 블록의 닫기 태그를 생략할 수 있으며, 때로는 유용합니다. include나 require를 사용할 경우, 원하지 않은 공백이 파일 마지막에 들어가지 않게 함으로써, 나중에 추가 응답 헤더를 추가할 수 있습니다. 또한 출력 버퍼링을 사용할 경우에도 포함한 파일들에 의해서 각 파트의 마지막에 원하지 않은 공백을 피할 수 있으므로 도움이 됩니다.
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.
If you want to keep the newline after a closing tag in the output, just add a space after the closing tag, and the newline will not be ignored.
One thing to remember is, if you decide to omit the closing PHP tag, then the last line of the file should be ended with semi colon. If you add the closing tag then last line doesn't need to end with semi colon.
<?php
echo "First line";
echo "Last line"
The above code throws error as it neither has closing tag nor semicolon ending. So it should be replaced with either of the below two
<?php
echo "First line";
echo "Last line";
or
<?php
echo "First line";
echo "Last line" ?>