PHP Syntax
Here is a clear and beginner-friendly guide to PHP Syntax
⭐ PHP Syntax (Basic Rules You Must Know)
PHP Syntax is always executed on the server, and the result is sent to the browser as HTML.
1. PHP Script Starts and Ends With Tags
Every PHP code must be written inside:
Example:
2. PHP Statements End with semicolon ;
3. PHP is Case-Sensitive
-
Variables are case-sensitive
-
Keywords, functions, classes are NOT case-sensitive
Example:
4. PHP Can Be Embedded in HTML
5. echo & print – Used for Output
Both work the same, echo is slightly faster.
6. PHP Comments
Single-line:
Multi-line:
7. PHP Variables
Rules for variables:
-
Start with $
-
Must start with a letter or underscore
-
Cannot start with a number
-
No spaces
8. PHP Keywords (reserved words)
Cannot be used as variable names:
if, else, function, class, switch, for, while, echo, etc.
Example (❌ wrong):
9. PHP Whitespace is ignored
Spaces, tabs, new lines do not affect the program:
Both will work.
10. PHP execute on server, HTML on client
This:
Outputs this in browser:
