Introduction to PHP

Introduction to PHP

PHP is a server-side scripting language that is also an interpreted language. It is basically used for developing software applications that have dynamic content and require constant interactions with databases. It is an open-source language making it one of the most sought platforms for developers and companies.

Features and Advantages

  • The performance of the scripts written in PHP is much better than those written in other languages like JSP and ASP.
  • Being open source, we can develop and maintain our applications without incurring any cost.
  • PHP is a platform-independent language, i.e., it can run on any OS without any problem
  • PHP code can also be embedded into HTML tags and scripts.

PHP Tags and the parsing engine

The code written in the PHP script is executed using the PHP parsing engine. The PHP parsing engine needs a way to differentiate the PHP code from other elements in the page.

The mechanism by which this occurs is known as escaping to PHP. There are four ways to identify php script.
1. The common php tag
    <?php [Required code here] ?>
2. From javascript code
    <script language=”php”>   [Required code here]   </script>
3. Short versions of tags
    <? [code here] ?>
4. ASP style tags
    <% [code here] %>

Commenting in PHP code:

A comment is a piece of code that is not executed by the compiler rather it is there just for the human reader to read. Comments in general are used to explain the code better and improve the readability of the code.

There are multiple types of comments:

Single Line Comments

Single-line comments are used to provide short explanations or points related to the code.

<? //This is a comment ?>

Multi-line comments

Multiline comments are used to provide more detailed explanations about the code whenever necessary. This system of commenting is same as the system of commenting in C

<? /*This is a multiline comment */ ?>

We can also run php scripts from our command prompt by referring to the file the php script is stored in

Let us assume there is a php file with the name test.php which holds the script

<?php Echo “Hello world!!”; ?>

We run this script in the command line in the following way $php test.php It will produce the result Hello world!