Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

2. PHP Syntax & Comments

Lesson 2 of 29 in the free PHP Programming notes on Siksha Sarovar, written by Rohit Jangra.

Default Syntax of PHP

PHP code is written inside PHP tags and executed on the server.

Basic PHP Syntax

<?php
   // PHP code goes here
?>

Important Rules

  • PHP statements end with a semicolon (;)
  • PHP is case-sensitive for variables
  • Keywords like echo, if, while are not case-sensitive

Example

<?php
echo "Welcome to PHP";
?>
Exam Point: PHP code must be written inside <?php ?> tags.

---

Styles of PHP Tags

PHP supports different tag styles to write PHP code.

1. Standard PHP Tags (Recommended)

<?php
echo "Hello PHP";
?>
  • Verified: Most commonly used
  • Verified: Supported on all servers

2. Short Open Tags

<?
echo "Hello PHP";
?>
  • Warning: Not recommended
  • Warning: May be disabled on some servers

3. Short Echo Tags

<?= "Hello PHP"; ?>
  • Use: Used for quick output
  • Support: Mostly supported in modern PHP versions

4. ASP Style Tags

<%
echo "Hello PHP";
%>
  • Status: Deprecated
  • Status: Not used in modern PHP

Comparison Table

Tag TypeUsageRecommendation
Standard<?php ?>✅ Best
Short Open<? ?>❌ Avoid
Short Echo<?= ?>⚠ Limited
ASP Style<% %>❌ Not used
Exam Tip: Standard PHP tags are the safest and most recommended.

---

Comments in PHP

Comments are used to explain code and are ignored by the PHP interpreter.

1. Single-Line Comment

// This is a single-line comment
# This is also a single-line comment

2. Multi-Line Comment

/*
This is a
multi-line comment
*/

Why Use Comments?

  • Improves code readability
  • Helps in debugging
  • Useful for documentation
Exam Line: Comments are non-executable lines used to explain PHP code.