PHP is a server-side scripting language that runs on the web server, not in the user’s browser.
When a PHP script is executed, it processes the code on the server and sends back plain HTML to the browser, which is then displayed to the user.
PHP code can be embedded anywhere within an HTML document, making it highly flexible for web development.
The syntax of PHP starts with <?php and ends with ?>, allowing developers to seamlessly mix PHP with HTML.
Files that contain PHP code use the .php extension.
Each PHP statement typically ends with a semicolon (;), which is an essential part of the syntax.
One of the convenient features of PHP is that its keywords—such as if, else, and echo—along with class names, function names, and user-defined functions, are not case-sensitive.
This makes the language easier to write and understand for beginners.
PHP Comments Explained
Comments in PHP are used to hide parts of code from execution. They help developers remember what the code does and make it easier for others to understand and maintain the code. Comments are only visible on the developer side and are not shown to users in the browser.
PHP supports two types of comments:
1. Single-line comments
These start with // or #.
<?php
// coding is fun
echo "Hello World!";
?>
<?php
# coding is fun
echo "Hello World";
?>
2. Multi-line comments
These start with /* and end with */.
<?php
/*
This is a multi-line comment
*/
echo "Hello World!";
?>
