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.
Como no C ou Perl, o PHP requer que as instruções sejam terminadas com um ponto-e-vírgula ao final de cada comando. A tag de fechamento de um bloco de código PHP automaticamente implica em um ponto-e-vírgula; você não precisa ter um ponto-e-vírgula terminando a última linha de um bloco PHP. A tag de fechamento do bloco irá incluir uma nova linha logo após, se estiver presente.
<?php
echo 'Isto é um teste';
?>
<?php echo 'Isto é um teste' ?>
<?php echo 'Nós omitimos a última tag de fechamento';
Nota:
A tag de fechamento de um bloco PHP ao final de um arquivo é opcional, e em alguns casos omiti-la é útil ao utilizar include ou require, assim espaços em branco indesejados não irão aparecer ao final dos arquivos, e ainda, será capaz de adicionar cabeçalhos a resposta. Também é útil se usar o buffer de saída, e você não gostaria de um espaço em branco indesejado ao final das partes geradas por arquivos incluídos.
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.
At the end of each statement,we will use a semicolon to seperate each statement.Php closing tag autometically implies a semiclon.So last line of a statment do not require a statement.
<?php echo "first statement";
echo "second statement"
?>
Closing tag is optional and some cases omitting the closing tag is very helpful.
1.using include or require function
2.unwanted whitespace will not occur at the end of file
3.add header any time
<?php echo "omitting closing tag";