PHP for Beginers: Introduction

Yesterday my friend from Cray Visibility challenged me. He asked me why haven't started teaching what I know best on my blog?

"Oh! What I know best?" I froze my face to inspect what he meant by that.

"Yes, you only talk about entrepreneurship and blogging, you never dare to see whatever your readers love to code." Deji replied.

Well, that was the conservation. But I doubt it actually goes that way, it's all in my head after all.

Even at that, I pondered overnight about his points, so I decided to start teaching Programming on this blog without quitting entrepreneurship and blogging.

What do you think about that? Comment below.

Anyways let's get started with my first programming language, PHP. Wait a minute...

What is Programming?

Programming is given structured and detailed instructions on how a computer(s) should execute a task. It is primarily more about thinking in abstractions on how a system can concurrently, procedurally or instantaneously address a given task.

In a rather less verbose but technical words, I mean you program by given a computer instructions on what to do simultaneously side-by-side, and what to do one step at a time, then instantaneously - doing something at the instant or presence of something else.

These definitions may not meant what is specified in the Oxford dictionary of English, but for me, it has captured all I have learnt about programming.

Programming Vs Coding?

This is a strong battle we should handle but proceeding. Many newcomers mistake coding for programming.

Well enough, the two ideas are interwoven but there is a slight shift we need to iron out. First, coding is about practice the art of writing in computer languages like Python, Swift, PHP, Ruby or name it.

The gist behind coding is that you want to get better typing in syntax of these languages. You may actually not be doing anything worthwhile. It is just you struggling with your codes.

When it comes to the proper use of the word programming, it is just about solving problems. It is more about thinking in abstractions and coming up with solution on how large projects connects, which data should your database primary key, should you go Object Oriented or leave it Functional?

Those are the questions that demands critical responses. You can learn a programming language overnight and stay coding in the language, hence you become a coder but you may not have become a programmer yet.

PHP and The Web

If you want be a web developer that could probably work on 80% of the world websites, you must learn the number web-server lingo, PHP (PHP: Hypertext Preprocessor).

It is a language that started out as Rasmus Lerdorf  sever side scripting language to mange his websites in 1994. The language gradually grow to become prolific for web development that top websites as Facebook, WordPress and Wikipedia had no choice (or maybe that have :}) than to use it.

The first reason why you should consider picking PHP is that it is excellently simple for newcomer. And more importantly, it have a very robust documentation.

Apart from the web, PHP can also do other functions as Command line scripting and Desktop App Development through the GTK project.

Enough of the talks, let's get started with data.

What are the Tools You Need?

First, you need to download and install PHP interpreter, follow the instructions give here. 

Second, get a nice text editor with a great autocomplete feature. I prefer you use Sublime Text or VS Code.

You already have a working browser, you don't need to download any specific one. The one you are using to red this article will do.

Everything is Data

Yes, in PHP and every other programming language you will later come across in your programming career, the simple fundamental is that every is data.

So what does programming help you do?

You program to manipulate, structure, encrypt, allocate, store, and retrieve data. It all starts with the input which is the the address of this article URL that you input into your browser and then you gain full access to this article.

I may as well secure this data, by asking you for username and password before you could read this article or pop a subscription to my mailing list out. All are data, and the manipulation of these data is the need to instruct the computer on how to utilize them.

So what does data look like?

Well from the Text you are reading, to the Audio you buy on iTunes, and lots of funny cats video you watch on YouTube. You are simply interacting with data, loads and loads of them.

In PHP, however, we primarily have eight data types.
  1. String
  2. Integer
  3. Float
  4. Boolean
  5. Array
  6. Object
  7. Null
  8. Resource
Let's explain all these data type and in later parts of this tutorial we will explore how they connect together.

Strings are long texts. It is simple a combination of characters wrap with single or double quotes.

Example: "My name is Timmy Brain", 'Hello World, I write PHP code'

 So let put this into use, open your SublimeText or Visual Studio Code (from now on I will refer to them as text editor).

Create a new document with Ctrl + N and save it as hello-world with PHP as the extension name.

Example filename:   hello-world.php

To start a PHP scripting, you will need a simple opening and closing tags. You should be familiar with what tags look like especially if you are not new to HTML too.

But the tags in PHP is quite different from that of HTML. It goes like this:
<?php #the opening tag

?> #the closing tag

The # is called the comments sign. Anything after the # is not read by PHP interpreter just like in most other programming language like Python, Ruby and C.

To be continue...


Post a Comment

Let me hear from you...