Syntax is relates to the right way to say or do things. PHP syntax stands for the right usage of the language tools and symbols.
PHP Syntax :
Since the introduction of the language in 1994 by Lerdorf, PHP syntax has taken time to develop and mature into a multifaceted development language.
In human language, there exists grammar rules that determine the validity of certain phrase construction techniques.
PHP syntax dictates what is right or wrong in the PHP language. The syntax is important because it is the standard way for the PHP parser to understand when to execute and when to escape in the flow of code.
There are four ways through which the parser identifies the beginning and end of PHP code.
- Canonical tags in PHP
- SGML-style (Short-open) tags
- ASP Style tags
- HTML script tags
Canonical tags in PHP :
This is the most common type. It is written as :
<?php … ?>
SGML-style (Short-open) tags :
One may also use the SGML tags shown below :
However, unlike the canonical option which is almost a standard, the SGML styled tags are a bit more complicated to set up.
The developer needs to –enable-short-tags configuration while setting up the PHP environment.
He or she also needs to configure the short_open_tag settings in the php.ini. It will only work when disabled to the XML parser as it uses the same for XML tags.
ASP Style tags :
If you are familiar with the ASP language, you may have noticed the usage of the percentage sign frequently.
The signs are used to mark various blocks of code. In PHP, they are used as follows:
The use of this kind of tag also needs to be defined in the php.ini file.
HTML script tags :
They are written as follows:
<script language= “PHP”>…Code block…</script>
Anything outside of the above tags will be ignored by the PHP parser. This feature allows for HTML tags to be added within the same PHP script or vice versa.
PHP Syntax Example :
The following code is meant to state someone’s age. However, there is a certain part that will be missing because it is not declared for displaying on the web browser.
Only information located within the php tags is considered for parsing. In addition, it must be inserted within the single quotes after the key word “echo.”
<h1>PHP Syntax page</h1>
echo "Hello World!";
PHP Syntax page Hello World!
Happy Learning 🙂