Home How Tos Basic Syntax Command of the PHP Programming Language

Basic Syntax Command of the PHP Programming Language

SHARE

A while ago, i started the tutorial on PHP which i promise to always update often but am sorry as some offline works / meeting took off my time but am ready to once again meet up with my vow and commitment to update about the topic once or twice a week.

Read Also: PHP Tutorial, Learning the Basic from Scratch

php_syntaxHaving explore the meaning and concept of PHP, today i will be looking into the basic PHP syntax. As we all know that in order  to create dynamic web pages, one will need to write some PHP code to achive such task. Using the right syntax, this will enhance a smooth work flow which can easily get debug in case any error arises.

The Echo Command:

The echo command is responsible for the output of the code display in browser. It sends any number of parameters separated by commas to the browser. Each parameters is converted to a string and displayed with no space between marks, the exact string within the quotation marks will be displayed.

The Print Command:

The print command is also also a command in PHP which is used to output to the browser but accepts only one parameter to output. However, the concatenation operator can be used to supply more than one parameter. The string to be displayed can be given within single or double quotation marks and can also be encapsulated within braces.

Guidelines for Writing PHP Code:

Just like with every other course and discipline, guidelines towards writing an error free PHP code must be adhered to, below are some of the guidelines we need follows.

1. All PHP code must be encapsulated within the start and end tag (<?php and ?>) for the Zend engine to recognize them as PHP code. There are three sets of start and end tags available.

  • The <?php and the ?> tags are the most preferred set of start and end tags
  • The <? and ?> tags are most commonly used to encapsulate the PHP code. To use these tags, one must enable short_open_tags in the PHP.ini file because its disabled by default.
  • The <script language = “php”> and the </script> tags can also be used.

2. Every line of PHP code must end with a semicolon (;). There are some exceptions to this rule.

Example Exercise:

You are a web developer new to PHP and want to create PHP code for displaying the text “Hello World” on the browser.

You need  to start the PHP code wit any one the PHP opening tags so that the browser can recognize and interpret the script as PHP code.

You will then use the output command (echo) to display the output on the browser.

You then end the statement with a semicolon.

Finally you enter the corresponding PHP closing tag to denote end of the PHP code.

<? php

echo “Hello World”;

?>

I will discuss detailed in next tutorial about using the basic syntax of PHP and implementing HTML and PHP interwoven. Feel free to drop your opinion via the comment box and share with any of the social media button below if you enjoy the article, till next tutorial.

 

Leave a Reply