PHP - Introduction

PHP - Introduction

This is the beginning of my study journey with PHP

Well, I've been working with PHP for a long time. But I always felt that I never took the time to really study it properly. In this PHP series, I will be sharing with you everything I'll be learning in the next months.

Origin

PHP stands for "PHP: Hypertext Processor" and was created by Rasmus Ledford in 1995. Basically, it is a server-side programming language, where every script is executed on the server and the result is delivered to the client.

Ledford while in college, developed a small piece of software that allowed him to count how many persons visualized his online CV. This script made in Perl became very popular, and he was willing to distribute it for free to anyone interested. Shortly after this, he began to add new features like database connection.

But it was not until the creation of the Zend company (which oversees and takes care of PHP as a language) when PHP started to consolidate as a real programming language. The founders of this company are Zeev Suraski and Andy Gutmans, and they put their work to establish PHP as a programming language with PHP 3.

Versions

In May, 2000, PHP 4 is launched, which includes the ZEND engine 1.0. 4 years later, on July 13th, 2004, PHP 5 is launched with the brand new ZEND engine 2.0.

From this point and onwards, small changes were made to the PHP programming language. As an example, we have PHP 5.4 appearing on May 8th, 2012. At this time it was also released a brief of what could be PHP 6, but this version was never released.

PHP 7 was released on November 3rd, 2015 and came with the Zend Engine 3.0. After that, several small version incrementes were released: 7.1, 7.2, 7.3 and finally 7.4. The latest is the only 7.x PHP version which still has active support.

On November 26th, 2020 PHP 8 was finally released.

How does PHP work?

  1. Client makes a request to the server, requesting for a file with .php extension
  2. The server read the code of the selected file, where it finds the PHP tags and calls the interpreter
  3. PHP reads line by line between its tags, execute the actions and returns the information as HTML content
  4. Client only receives HTML content, and never gets to access any of the .php files
  5. Client's browsers reads the HTML and displays it on screen

Our first code in PHP

We have learned a lot about the history of PHP, but now let's get to the code. So, first of all, how can we create a 'Hello World' in PHP? It is actually very simple, just save this code inside any .php extension file and then execute it:

<?php 
echo 'Hello World';
?>

Mixing PHP + HTML

PHP brings us the possibility to include HTML tags inside the PHP scripts. Here is an example:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>This is a Heading</h1>
<p><?php echo 'This is a paragraph'; ?></p>

</body>
</html>

Comments

There are a few ways to create comments inside our PHP code:

We have the single-line comments

<?php

// This is a comment
# This is also a comment

?>

And we have the multiple-line comment as well

<?php

/*
This is a multiple line comment
in PHP
*/

?>

On our next chapter, we will be learning about different types of data representation and variables in PHP ;)