Getting an Overview of PHP

Kayla Grieve
6 min readJan 28, 2018

--

Photo by Kevin on Unsplash

I will have to let you know I have been trying out a new language. No not like English or anything like that but a programming language for those of you who are not familiar and are reading this. I have been trying to learn PHP. I did this because I wanted to learn something that related to the job market and it seemed that PHP was mentioned and it was important to the job I was applying to. So I thought hey let’s learn this. I am extremely new to PHP but I am going to try my best to explain it. There will be two more parts to this blog coming later. First let’s get to what PHP is all about and where it came from.

History of PHP

PHP/FI died and PHP rose from its ashes. Ok maybe that was a little to dramatic but PHP essentially came from PHP/FI and was created by Rasmus Lerdorf. History gets hard to read so I wanted to make it a bit more fun. Soooo One day Rasmus wanting to track visits on his online resume came up with an idea! What was the idea you ask? He decided to combine these scripts he made in C with more tools that would allow websites to have their own guest books and database interaction. At this time it was called “PHP tools”. As the years passed PHP tools grew into PHP/FI then just FI (Forms Interpreter) and finally the PHP language. I think you get it. It took a long time before it actually became the language you see today.

What is PHP?

PHP Stands for Hypertext Preprocessor but wait what happened to the other p? Apparently PHP is a recursive acronym and the first letter stands for itself. So it’s PHP: Hypertext Preprocessor and the PHP originally stood for “Personal Home Page”. This was back when Rasmus created it for his “Personal” information. Ok we know what it stands for now but that’s break it down further. Hypertext is text that have links to other pages of text. Preprocessor “pre” meaning it does its “processing” before the hypertext is sent to the user.

Why use it?

PHP is a great language to learn if you are a beginner because it is easy to learn but it also has something to offer people at a much more advanced level as well. One of the reasons it’s one of the easiest to learn is because it is one of the most well documented languages with comments from other users adding to the understanding of the language. It is also free for those who are worried about cost. It is versatile in databases that it can work with, mysql being one of those. It is also very important to learn because many companies and popular websites use PHP even today(Facebook).

Those who already know HTML can add PHP to their HTML websites to create a more interactive site. PHP can help validate users, run discussion threads, serve xml pages, help with forms, save cookies and much more. PHP can be used within HTML code like the following example:

<head></head><body><?php echo “Hello”; ?>.</body></html>

It can also be used outside HTML like this:

<?php$Fname = $_POST[“Fname”];$Lname = $_POST[“Lname”];?><html><head><title>Personal INFO</title></head><body><form method=”post” action=”<?php echo $PHP_SELF;?>”>First Name:<input type=”text” size=”12" maxlength=”12" name=”Fname”><br />Last Name:<input type=”text” size=”12" maxlength=”36" name=”Lname”><br /></form><?echo “Hello, “.$Fname.” “.$Lname.”.<br />”;?>

(Example taken from: https://www.ntchosting.com/encyclopedia/scripting-and-programming/php/php-in/)

It is interesting to note that when the user looks at the elements of a website they only can see the HTML and not the PHP.

Advantages and Disadvantages

We should start with the advantages! One of the advantages to PHP is that it is stable since it has many developers working on it and has been around for a long time bugs are usually fixed relativity fast. It also has a great library support where you can find many functionalities that you might want to use when working with PHP. Those who worry about what platform they use and its compatibility, worry not! PHP can work with Mac, Windows, Linux and more, so it has variety. PHP also can decrease the amount of time spent on developing web apps because it has built in database connection modules. Do you like fast loading websites? Of course who wouldn’t! Well that is another reason why developers like using PHP because of its speed!

Ok and the Disadvantages. Its security is at a disadvantage because it is open source and so people can look at the code and find bugs and weaknesses. PHP is only good with small projects because it is very modular and would be hard to maintain if it was a large project. Another problem is the errors; PHP does not have very good debugging tools and has very poor error handling.

HTML v.s PHP

You might be wondering what the difference between the two? We will get to that but first that’s list the similarities. They both can work with AJAX to make dynamic websites and to me as a beginner they look similar. You could say PHP has HTML’s back since it works on the server side (back-end) while HTML works on the client-side (front-end) and this is one way they differ. HTML is more relaxed, it’s the kind of friend that will let you make mistakes in its code and still display something on the screen. However PHP is pickier if you did something wrong in its code it will not produce an output for you. HTML is a markup language where PHP is a scripting language.

Similar code to other languages

I wanted us to take a look at code that is similar to other languages because I believe it’s easier to learn something new if you can relate it to something you already know. This is where I started and I think it might help you to! PHP is similar to Java in that the loops, if statements, switches are almost exactly the same as here are some examples shown below: (Note: I will be going through the basics later on in my blog series so that’s just focus on what’s familiar)

<?php 
$variable = 1;

while($variable < 20) {
echo “The number is less than 20 still”;
$variable++;
}
?>
<?php$variable = 1;

if ($variable < 20) {
echo “Your number is less than 20 yay!”;
}
?>

The basic structure is the same as it is in Java so look at that you already know some PHP. There are other languages that are similar such as C, C++, C# and Perl but I will just stick with Java for now and will not display the similarities here.

How does PHP work with the server?

Now that we know what PHP is and how it relates to HTML and other languages we can start to learn how it works with the server. When a user first comes to a site, a GET request is sent to the server. The sever will then find the file and recognize PHP files by their extension PHP for an example “home.php”. The server then sends the file to the PHP interpreter where it is parsed, compiled and is executed. The PHP interpreter does this one line at a time and then the results are sent back to the server and then to the browser.

Coming up next!

This blog went through the information side to get a basic overview of the language. I learn better when I know the information behind the code I know some people are the opposite and we will tackle that next. The next blog we will be looking at the basics of actual coding.

--

--