OnlineCBT Logo OnlineCBT
PHP · LESSON 2

PHP Syntax, Comments, and Echo / Print

By Ratan Updated: 16 Oct 2026

Understand <?php ?> script tags, line termination, comments, and outputting data with echo vs print.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

1. PHP Syntax and Tag Structure

PHP code blocks are written inside the standard opening tag and closing tag ?>. If a file contains exclusively PHP code, it is recommended best practice to omit the closing tag ?> to prevent accidental whitespace or newlines from causing header errors.

 if file contains only PHP code

2. Semicolons and Statement Termination

Every PHP instruction or statement must terminate with a semicolon (;). Forgetting a semicolon is the most common cause of Parse Error: syntax error, unexpected token in PHP.

3. Comments in PHP

PHP supports single-line and multi-line comments for code documentation:

4. Output Mechanisms: echo vs print

Both echo and print are language constructs used to display output to the screen, but they have subtle distinctions:

Feature echo print
Return Value Has no return value (void). Always returns 1, allowing it to be used in expressions.
Arguments Can take multiple parameters separated by commas. Takes only one argument.
Performance Marginally faster than print. Slightly slower due to returning a value.
";
echo "Parameter 1", ", ", "Parameter 2
"; // Using print print "Printed with print statement
"; // Short echo tag inside HTML templates // is equivalent to $pageTitle = "Dashboard"; ?>

5. Case Sensitivity Rules in PHP

  • Variables are case-sensitive: $color, $Color, and $COLOR are three completely different variables.
  • Keywords, function names, and class names are case-insensitive: echo, ECHO, if, IF, count(), COUNT() resolve to the same instruction. However, maintaining consistent lowercase syntax is the professional convention.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
Address Contact

+91 7877547686

E-mail

onlinecbtportal@gmail.com

Helpline Number

+91 7877547686


Click To Download
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat