PHP – Syntax
The PHP script is executed on the server and the HTML result is sent to the browser. It can normally have HTML and PHP tags. PHP or Hypertext Preprocessor is a widely used open-source general-purpose scripting language and can be embedded with HTML.
A “.php” file may contain HTML, CSS and JavaScript code blocks along with the PHP code. Hence, the PHP parser must differentiate between the PHP code from the other elements. When a “.php” file is opened in the web browser, the HTML engine renders the HTML/CSS/JavaScript part and escapes out of the HTML block as soon as the statements included in PHP tags are encountered. The PHP parser interpreter processes this block and returns the response to the browser.
PHP Case Sensitivity
In PHP, keywords (e.g. if
, else
, while
, echo
, etc.), classes, functions, and user-defined functions are not case-sensitive.
In the example below, all three echo statements below are equal and legal:
<!DOCTYPE html> <html> <body> <?php $color = "red"; echo "My car is " . $color . "<br>"; echo "My house is " . $COLOR . "<br>"; echo "My boat is " . $coLOR . "<br>"; ?> </body> </html>
Canonical PHP Tags: PHP – Syntax
The script starts with <?php and ends with ?>. These tags are also called ‘Canonical PHP tags’. Everything outside of a pair of opening and closing tags is ignored by the PHP parser. The open and closing tags are called delimiters. Every PHP command ends with a semi-colon (;). Let’s look at the hello world program in PHP.
Comments in PHP:
Comments help in reminding the developer about the code if it’s re-visited after a period of time.
Single Line Comment: As the name suggests these are single line or short relevant explanations that one can add to their code.
Multi-line or Multiple line Comment: These are used to accommodate multiple lines with a single tag and can be extended to many lines as required by the user.