downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

주석> <HTML에서 벗어나기
[edit] Last updated: Sat, 07 Jan 2012

view this page in

명령 구분

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

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

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

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

Note:

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



주석> <HTML에서 벗어나기
[edit] Last updated: Sat, 07 Jan 2012
 
add a note add a note User Contributed Notes 명령 구분
pbarney 17-Nov-2011 05:13
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.
Darabos, Edvrd Konrd 19-Aug-2008 05:58
One newline character (or sequence) is dropped out by the parser after "?>", so you can add the beloved "final newline" to your file after "?>"

Example for plain text outputs:

<? foreach($array as $elem){ ?>
Value: <?=$elem?>

<? } ?>

(You have to add an extra enter after <?=$elem?> if you want to see a newline in the output.
james dot d dot noyes at lmco dot com 05-May-2008 01:42
If you are embedding this in XML, you had better place the ending '?>' there or the XML parser will puke on you.  XML parsers do not like processing instructions without end tags, regardless of what PHP does.

If you're doing HTML like 90% of the world, or if you are going to process/interpret the PHP before the XML parser ever sees it, then you can likely get away with it, but it's still not best practice for XML.
Krishna Srikanth 17-Aug-2006 06:44
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.

 
show source | credits | sitemap | contact | advertising | mirror sites