/    Sign up×
Articles /Pin to ProfileBookmark

What is PHP | How to Write Your First PHP Program ?

In this article, I will explain what PHP is and how to run your first program with. Also, I will discuss in-depth the history of the PHP interpreter and how it works.

PHP is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

Let’s discuss how was the PHP interpreter working in the past.

Zend Engine

History of PHP Interpreter

The first appearance of PHP was in 1994, created by Rasmus Lerdorf. During this time, PHP was only using as a personal use.

The PHP duty in this time was tracking and collecting the number of visitors who are visiting the resume of Rasmus Lerdorf.

And the parser was only translating a few characters and some numbers

The first generation of PHP interpreter was known as the PHP/FI.

In the following block, you will see, how was the PHP/FI coding.

<!--include /incs/get_header.html-->


<!--Hello <!--$user_name-->, Welcome to your home page.-->

<!--include /incs/get_footer.html-->

However, PHP was started to spread far and wide in the beginning of 1996.

The updates in this generation were two packages been added, and the interpreter named as the PHP/FI Version 2.

The two packages were FI and mSQL, the first one was referring to the Form Interpreter and that was interacting with form inputs and validation

On the other hand, the second package mSQL was interacting and handling the databases.

The following code shows you, How m SQL was working in the PHP document.

<!--sql database update users set where username='$username'-->

Anyway, PHP became as the famous scripting language in the planet for web development. And that because it has more than 75% of websites using it.

In the next section, I will explain the PHP interpreter steps in-depth. Let’s dive right in.

How the PHP Interpreter Works

In a quick overview, there are many differences between the compiler and the interpreter.

We have to focus only on the part of what is happening in the source code to continue our explanation about the PHP Interpreter.

The compiler is translating the source code in one shot, which is receiving the full source code and start the compiling.

In the contrary, the interpreter translating the source code by a statement, which is line by line.

PHP interpreter is a program that takes the source code from the server and executing it through four phases.

Then send us the final result and that can be done by the web browser to embed it inside the HTML markups.

Anyway, The PHP interpreter is generated by Zend company. They named it Zend Engine. In this program, the source code is taking four phases. Let’s take each one in details.

The Tokenization (The lexical analysis)

In this stage, the web server is sending the source code to the lexer and that to scan the inputs and generating the sequence of tokens.

Consider we have a PHP code like the below one


  $number = 5;
  echo $number;


And we need to see how the lexical analysis works on. The following list shows you the steps to organize the final strings.

  1. Scanning the source code.
  2. Searching about the common names of lexical analysis stage such as identifiers, comments, operators, literal, separator, and so on.
  3. Organizing the PHP code according to the previous lexer common names.
  4. Generating the list of tokens and send it to the parser.

Overall, the lexical analysis removes the white spaces, lines, comments, and checks for errors in the source code before sending it to the following phase, and then produces the sequence of tokens.

If it found an error in the source code, the interpreter will show only a message without terminating the process.

So the final characters would be like the following token.

  ( operator, '$' ),
  ( identifier, 'number' ),
  ( operator, '=' ),
  ( literal, '5' ),
  ( operator, ';' ),
  ( keyword, 'echo' ),
  ( operator, '$' ),
  ( operator, 'number' ),
  ( operator, ';' )

As you saw, all white spaces and lines are removed from the source code.

Also, organized the source code according to the common names of the lexical analysis.

Then it sends the full characters to the following step.

The Parser

The parser is receiving the list of tokens and starts the Zend Engine VM (Virtual Machine) to process the lexical tokens. And sends it to the compilation.

The Compilation

This step is already working under the parser, it generates the Abstract Syntax Tree to optimize the processing.

And in the following step, it creates something called the operation codes or OP Codes. This is similar to the assembly language mission.

The Execution

Here, the executor takes the intermediate codes and set an array to read and execute the instructions inside this array.

In the following few lines, you will know what is PHP program and how to run it through your local machine.

How to Write your First PHP Program

Actually, the PHP program is a web application depending on an open-source scripting language called PHP, which means a personal home page or hypertext preprocessor.

Before starting your web application, you have to install Xampp server or Wamp server. Or use our online PHP Compiler.

Once decided what you will do, let’s see how to run your first PHP program.

Anyway, I am using Xampp server on my local machine. And I am going to print this message – “Hello Web Developers”.

Open the htdocs folder on your OS and create a new folder, then name it – “test”. And the following step, create a file and name it index.php.

Then copy and paste the following code into the index.php file

<?php    echo "Hello Web Developers."; ?>

Open your web browser and then navigate to this root – “localhost/test”.

The output would be like the below result.

Hello Web Developers.


In this article, you understood what PHP is and how was it working on the past. I also explained the Zend Engine phases.

In addition, you learned how to run your PHP application on your local machine.

Stay tuned for my next articles.

This article published by CodedTag. Thank you for reading.



Help @mich spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 2.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ

legal: ({
terms: of use,
privacy: policy
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
recent_tips: (
tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,

tipper: @neststayhome,
tipped: article
amount: 1000 SATS,