Introduction To PHP

Php is a server side scripting language .It is generally used to create websites but beside that we can also use Php to develop tools as well as we can use it to create website.It is an opensource language and is widely used by many developers.It is a simple programming language with easy syntaxes which makes it easy for anyone to learn and apply it.In this guide we will cover below topics :

  • What is Php
  • History of Php
  • Importance and relevance of Php in webdevelopment
  • How can we use Php
  • Basic Php Example

What is Php

  • Php is opensource scripting langauge
  • Php is free to download as opensource
  • Php is executed on server side
  • Php is easy syntax to use
  • Php can be embedded with HTML code
  • Php contain number of in-built functions for strings,arrays ,error-reporting which helps in writing code easily
  • There are several Php framewrks like Codeigniter,Laravel which has many in-built libraries and code which helps in scaling and building applications easy
  • Php can be used to build dynamic websites,webapps and can also be used to create APIs

History of Php

  • In 1994 Canadaian programmer known as Rasmus Lerdorf initally created PHP and named it as Personal Home Page as it was used only to track the users online who visits his personal webpage
  • In 1995 Rasmus integrated basic functionality for dynamic webcontent and interactivity with databases.He then in the same year make the source code publicly open for any one.So it become a opensource language which can be used by any one.
  • In 1997 the Php parser which constitues the core of PHP was rewritten by 2 dvelopers Zeev Suraski and Andi Gutmans and PHP was now named as PHP version 3
  • In 1998 PHP 3 got officially released and it became popular as it supported many databases and protocol and was best suited for webdevelopmentIt was now renamed as “Hypertext Preprocessor”
  • The core was more evolved by the 2 developers and it was named as Zend engine and it was more powerful than previous core .
  • In 2000 PHP 4 was released and it gain more popularity because of it versatility.
  • In 2004 PHP 5 was introduced and with that come the Object oriented programming was introduced in the language.
  • Eventually PHP got evolved and new version like PHP 7 and Php 8 came with many more features like JIT compiler and performance improvements.
  • Currently we have PHP 8.1 and 8.2 with various features like enums, readonly properties, and further performance optimizations.

Importance and relevance of Php in webdevelopment

  • Php is server side language so it can manage sessions,manage database operations and backend functionaities easily so we can create dynamic data.
  • Php is opensource language so anyone can contribute to this language.Its also free to download so development costs becomes less.
  • Php can be connected to any database making it easy to create dynamic data driven applications.
  • Php is not limited to website development ,it can be integrated with new technologies like React,Vue and Angular giving a flexibility to create RestAPI and microservices and other modern web applications.
  • There is big support of Php community which means a big support of resources,frameworks,tools and support.
  • Php supports different platforms like Windows,Os and Linus so we can say that it is compatible in any environment.

How Can We Use Php ?

  • Php can be used to create forms to collect data and save it in database.
  • Php uses sessions so we can create applications which needs to maintain state of user.
  • Php can handle file manipulation on server side like creating files,reading files and writing files.
  • Php can be used to get information of other websites using cURL (php in-built library)
  • Php can be used to upload imags and encrypting passwords for applications.

Basic Php Example

Php uses simple syntaxes.Lets go through some basic syntax which we will use here to print a text.

Php files which contain code is saved with .php extension .In Php any code is written between opening and closing tags of php. Any code which is written in between these tags is known as statement.Every statement in the code ends with a semicolon.Below you can see the opening and closing tag example.

<?php // This is the opening tag

?>   //This is the closing tag

Now we want to display some text on the screen using php code.So for this we will go step by step process.

To write this program we need few things.The first thing which is most important is that you must have xampp installed in your local PC.xampp is an opensource distribution which has Php,MariaDB and Perl.By installing this you will get database connection and php installed so that you can work locally.On installing this you will get htdocs folder installed in your PC by running xampp exe file.This htdocs folder is the one which contains all the source code.WE create here folder and save php files here.To run this we need to start our xampp control panel.Then in browser you have to simply type http://localhost[your-folder-name]/filename.php.And you are done .LEts check the example code below to simply display a message text on the screen.

First we need to create a blank php page say index.php in a folder say php_first_program in htdocs folder.Now we will write some code to display data on screen .In php as we know there are many in-built functions that we can use to write code.In Php echo ,a language construct is present which is used to output any data to screen.In echo we need to only add the data we need to display on screen within a single or double quote.There is also a function print which we can use to display output data on screen.But here we will be using echo.Check the example code below :

<?php
echo 'Welcome to Php Guru Academy';//This is a statement
?>

The output of this code will be : Welcome to Php Guru Academy

Check the screenshot below

Php Program To Display A message On Screen

Leave a Comment

Scroll to Top