Basic PHP syntax: tags and comments
Study notes on PHP's basic syntax, based on the official manual: the opening tags used to delimit PHP code and the comment styles available in the language.
Tags
Main tags:
<?php ?>— the most recommended one<?= ?>
1. <?php echo 'se você deseja rodar código PHP dentro de documentos XHTML ou XML,
utilize essas tags'; ?>
2. Você pode utilizar a tag curta <?= 'imprima essa string' ?>.
É o equivalente de <?php echo 'imprima essa string' ?>.
3. <? echo 'Este código está entre tags curtas, mas somente funcionará '.
'se short_open_tag estiver ativo'; ?>
Short tags (example 3) are available by default, but can be disabled through the
short_open_tagdirective in the php.ini configuration file, or disabled by default if PHP was compiled with the--disable-short-tagsconfiguration.Since short tags can be disabled, it's recommended to use only the regular tags (
<?php ?>and<?= ?>) to maximize compatibility.
Comments
<?php
echo 'Isto é um teste'; // Comentário de uma linha no estilo C++
/* Este é um comentário de múltiplas linhas
ainda outra linha de comentário */
echo 'Isto é ainda outro teste';
echo 'Um teste final'; # Este é um comentário de uma linha no estilo shell
?>
Single-line style comments only comment out to the end of the line or of the current PHP code block, whichever comes first. This means the HTML code after // ... ?> or # ... ?> WILL be printed: ?> breaks out of PHP mode and returns to HTML mode, and // or # cannot influence this.