Syntax In PHP
Learners will benefit from today’s blog post on PHP Syntax. It aims to provide a clear and concise guide with examples to help individuals understand the basics of the PHP language and its syntax. This post is suitable for beginners and those looking to improve their skills.
The PHP script runs on the server and provides the plain HTML result to the web browsers.
PHP Syntax Basics
There is no restriction on where a PHP code can be placed in a document.
There are two parts to a PHP code: the beginning <?php and the end ?>. These tags are the primary structure for any PHP code.
The PHP code must be written between these tags as shown in the examples below:
Files written in PHP are saved using the “.php” file extension.
PHP files often include a combination of HTML and PHP code.
The following examples shows two basic PHP script displaying the text “Lionel Messi is a famous footballer” and “Lionel Messi has confirmed that the FIFA 2022 will be his last World Cup ”on a page using the PHP function “echo“:
Remember: Statements in PHP must end with a semicolon (;).
Case Sensitivity for PHP
PHP does not apply case sensitivity to keywords, classes, functions, or user-defined functions.
This means that “if“, “If“, and “IF” are treated as the same keyword, and the same applies for other keywords, classes, functions, and user-defined functions.
Please note that case is sensitive when naming variables!
As you can see in the example below; only the last statement will display the value of the $game variable!.
This is because $Game, $GAME, and $game are treated as three different variables: