You should always use <?php ?> tags or short-echo tags <?= ?>. Other variations (in particular, short tags <? ?>) should not be used as they are commonly disabled by system administrators.
When a file is not expected to produce output (the entire file is PHP code) the closing ?> syntax should be omitted to avoid unintentional output, which can cause problems when a client parses the document, in particular some browsers fail to recognise the <!DOCTYPE tag and activate Quirks Mode.
Example of a simple PHP script:
<?php
print "Hello World";
Example class definition file:
<?php
class Foo
{
...
}
Example of PHP embedded in HTML:
<ul id="nav">
<?php foreach ($navItems as $navItem): ?>
<li><a href="/?originalUrl=https%3A%2F%2Friptutorial.com%2F%26quot%3B%26lt%3B%3F%3D%2520htmlspecialchars(%24navItem-%26gt%3Burl)%2520%3F%26gt%3B%26quot%3B%26gt%3B%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%26lt%3B%3F%3D%2520htmlspecialchars(%24navItem-%26gt%3Blabel)%2520%3F%26gt%3B%2520%2520%2520%2520%2520%2520%2520%2520%26lt%3B%2Fa%26gt%3B%26lt%3B%2Fli%26gt%3B%2520%2520%2520%26lt%3B%3Fphp%2520endforeach%3B%2520%3F%26gt%3B%26lt%3B%2Ful%26gt%3B%253C%2Fcode">