Introduction
PHP Hypertext Preprocessor (PHP) is the most popular server-side scripting language on the world wide web. This guide is designed to introduce programmers familiar with other programming languages to PHP.
This guide will take the form of a series of posts that will cover PHP from the basics to intermediate level. In this post I will cover code delimiters, comments and PHP statements.
How PHP code is executed
PHP is an interpreted language. PHP code is placed in simple text files usually having .php extension. PHP code can also be placed alongside HTML code in the same file. This is one of the strongest features of PHP. PHP code is diffrentiated from the rest of the HTML code by the delimitation used.
Delimiting PHP code
PHP code is place within the <?php and ?> delimiters. See the example given below
<?php
//php code here
?>
Commenting PHP code
Comments are used to annotate code. Any code that is placed inside a comment is ignored by the interpreter. Placing comments is a good idea because it helps other programmers follow your logic and also serves as a reminder to yourself of the same.
PHP has two types of comments similar to C++ comments. Single line comments begin // and end at the end of a line. Multiline comments begin with /* and end with */ . Examples of single line and multiline comments are given below
<?php
$x=$y; //This is a single line comment
//This is another single line comment
$x+=$x;
/*
-------------
This is a
multi line comment
-------------
*/
?>
PHP code statements
A code statement is a single PHP operation such as assigning a value to a variable. PHP code statements end with a semi colon. For ex:
<?php
$x=$y; //This is statement
$x+=$x; $x-=$y; //more than one statement may be placed on a line
?>
Thats all for now. I will cover more PHP coding topics in this blog in the future.