What is the correct & common way to start and finish a PHP block of code?

The correct and recommended way is the standard tags: <?php to start and ?> to finish.

<?php
echo "Hello from standard tags";
?>

Output:

Tutorials Class - Output Window

Hello from standard tags

There is also the short echo tag <?= ... ?>. It prints a value and it is always available (PHP 5.4 and above), so it is good inside HTML.

<p>Year: <?= date("Y") ?></p>
  • The old short open tag <? ... ?> works only when short_open_tag is On in php.ini. It is usually Off, so do not use it.
  • In a file that has only PHP code, leave out the closing ?> tag. It avoids problems with extra spaces after it.

See also PHP Syntax.


Learn more about the similar topics:
Tutorials
PHP Introduction
PHP Terminology
PHP Installation
PHP Syntax
PHP Comments
PHP exit() Function
Exercises & Assignments
Write a program to print “Hello World” using echo
Simple Tips for PHP Beginners
Experiment with Basic PHP Syntax Errors
Using phpinfo() – Display PHP Configuration & Modules
Interview Questions & Answers
What is PHP?
Who is the father of PHP?
What is the correct & common way to start and finish a PHP block of code?
What is Open Source Software?
What is the default extension of the PHP file?
What is the latest version of PHP?
What is the full form of PHP?