A set of commands is responsible for performing a particular action within the code, regardless of the chosen language. A command line indicates the action and the next, sequentially, will then be read, interpreted and enforced. But for this to happen it is necessary that the code interpreter has a point – character – indicating when actually one line ends and when starts another one.

As in C or Perl, PHP requires instructions to be terminated with a semi-colon at the end of each command. However, the closing tag of a block of PHP code automatically implies a semi-colon, it is not necessary to have a point-colon ending the last line of a PHP block. The closing tag will include a new line just after, if it is present.

Example:

<?php
echo ‘This is a test’;
?>

<?php echo ‘This is a test’ ?>

<?php echo ‘We omitted the last closing tag’;

The closing tag of a PHP block at the end of a file is optional, and in some cases it is useful to omit it, especially when using an ‘include’ or ‘require’. Thus, unwanted white spaces will not appear at the end of the files and you can still add additional response headers. This type of deployment is also useful if you want to use output buffering, where no one wants to have added a blank space at the end of the parts generated by the included files.

Separation of PHP

 

Despite the need not to use the PHP closing tag, it is important to pay attention to some points of use:

Example:

1)         <?php echo ‘Excluded PHP end tag’;

2)         <?php echo ‘Excluded PHP end tag’;
<p>HTML still visible</p>

In the first example, the code will function normally, as in the following example an error is displayed, whereas a HTML code is written immediately following, without the correct distinction of each type of code. Excluding the need to indicate the end of PHP code only in cases where there are no more code, HTML, for example following.

Another important tip is to use as separators in different lines, as shown in the following example:

<?php
echo “First Line”;
echo “Last Line”

The above code would generate an error since the first line possess a finalized command and the line below does not. It is necessary then rewrite this code in the following formats:

<?php
echo “First Line”;
echo “Last Line”;

or

<?php
echo “First Line”;
echo “Last Line” ?>

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.