My first dabble into PHP Programming language at Findworka Academy.

The journey as I set out being a software developer

I’ve always been enthusiastic about tech since age 14. I can remember my very first experience with computers and that was during my secondary school days. Although, the very first thing I ever did on a computer was to “play a game”, I have since been mesmerized at how a “then box looking machine” could be that interactive, entertaining and, do so much productive work.

Fast forward 15 years, the desire still burns, even more than ever and now in a more directed fashion.

I dabbled into software development about 2 years ago just after I had finished my first degree in psychology. I got introduced to HTML and CSS and it all seemed exciting not until I stumbled on a language I consider to be much more fun — Javascript.

Truth be told, it was pretty challenging to learn a programming language — understanding how logic works, defining a problem and actually translating that defined problem’s solution into a syntax that seemed foreign (Not English). The only thing that got me going was the idea of what I could do with the skill.

I still don’t consider myself there yet as I feel there’s quite a number of things I need to learn (imposter syndrome aside), and that’s one of the reason I set out to Findworka Academy! An academy dedicated to raising and mentoring people who are aspiring to becoming remarkable software developers.

My Dabble Into PHP

Prior to this time, I had been exposed to Javascript and a little bit of NodeJS (Javascript’s server side programming language) but not PHP (Hypertext Preprocessor).

What PHP is about — PHP is server-side scripting language and in “English”, it means a Programming language that can help us communicate with and from the server. Not all programming language can perform this task. Before the advent of NodeJS, JavaScript was a client side programming language alone, meaning it could only be used for manipulating the views and serving dynamic contents to the users only on the browser!

With PHP, you can collect form data, generate dynamic page content, or send and receive cookies. There’s a whole lot more we can do;

  1. Server-Side Scripting- To make this work, we need three things: PHP parser, a web server and a web browser. The web server is run only with a connected PHP installation and then you can access the PHP program’s output with a web browser and that means viewing the php page through the server. All this can run on a local machine as long as we have php installed.
  2. Command Line Scripting — With this, we don’t need a web browser or a web server to make it work. We can write Scripting with php that works on a computer’s CLI (command line interface) also known as the terminal. (Isn’t that amazing?)
  3. Building Desktop Applications — PHP can also perform this task, you’ll have to use the program’s advance features to make this work. Although, PHP isn’t the best language to use to build desktop apps, but it can still do the job.
Challenges are what gives us muscles…

Challenges and issues faced with writing PHP

Other than having to learn a whole new syntax, I’m not sure I have so much difficulty learning the programming language (that’s what happens when you seem to be familiar with another server side programming language).

I was amazed at the simplicity of PHP, I think of it as a programming language that makes life easier to perform certain task.

I’ll show you what I mean — Let’s go techy! (Don’t worry, it’s going to be basic)

User Story: I need to present a user with a form so that they are able to input their first and last name, and then, all I do is output the value of both input.

I’ll do this in JavaScript and in PHP, so you can see why php seems to be easier to write.

//JavaScript
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Getting Form Input Javascript</title>
</head>
<body>
<form>
<div>
<label for="firstname">First Name</label>
<input type="text" id="firstname" placeholder="Enter your firstname">
</div>
<div>
<label for="lastname">Last Name</label>
<input type="lastname" id="lastname" placeholder="Enter your lastname">
</div>
<input type="submit" id="submit">
</form>
<script>
let firstname = document.getElementById("firstname");
let lastname = document.getElementById("lastname");
let button = document.getElementById("submit");
button.onclick = ()=>{
alert(`${firstname.value} ${lastname.value}`);
}
</script>
</body>
</html>

Here in JavaScript, we had to select each of the input from the DOM (Document Object Model), add an event listener to the button and then do something with the result (in this case, alert the output). To run this, you can copy and paste the code in your favorite text editor, save (in this case, I saved mine as index.html) and open directly in your browser. Enjoy!

Let’s take a look at the same in PHP

//PHP
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Getting Form Input PHP</title>
<?php
if(isset($_GET["firstname"]) && isset($_GET["lastname"])){
echo "First name is ".$_GET["firstname"]." and last name is ".$_GET["lastname"];
}else{
echo "Provide First and Last Name.";
}
?>
</head>
<body>
<form action="/index.php">
<div>
<label for="firstname">First Name</label>
<input type="text" id="firstname" name="firstname" placeholder="Enter your firstname">
</div>
<div>
<label for="lastname">Last Name</label>
<input type="lastname" id="lastname" name="lastname" placeholder="Enter your lastname">
</div>
<input type="submit" id="submit">
</form>
</body>
</html>

It’s no surprise that the syntax is different, but the over all idea still remains the same. Here in PHP, we’re checking if the value of input is set with the isset() method. If they are both set, simply echo them as an output on the same page. Note the action="/index.php" on the form tag.

How do we view this? Remember PHP runs on a web server? So to run this code is slightly different, and interesting (since it has to do with the terminal). As long as PHP is installed in your PC, we can simply ask php’s web service to listen on a particular port number from the terminal. You can run this command directly in your terminal.

php -S localhost:3000

NB: To make it’s navigation easier, please note the directory you have your index.php file saved. Now, you can open the terminal on that same directory, then run the code.

You should see an out out like this. I ran mine in a folder called oluseyi on my desktop. Hence, it made that folder my Document root.

$ php -S localhost:3000
PHP 7.2.7 Development Server started at Sun Aug 5 09:51:18 2018
Listening on http://localhost:3000
Document root is C:\Users\Oluseyi\Desktop\Oluseyi

How do I view this in my web browser? simply type in the URL, http://localhost:3000 PHP looks in the root directory for an index.php file by default. So, there you have it!

Aside wrapping my mind on how the syntax works, it becomes much more easier to perform these tasks.

There are limitless applications to what I can do with this language and in the long run, I see myself building useful applications that users will love.

I hope you had a good read, enjoy the rest of your day!

--

--

--

Software Developer

Recommended from Medium

System Model Session 9

UNITY3D DEVS — SETTING UP YOUR MAC FOR ANDROID BUILDS

How I Use Obsidian As A Creative — Part 3

One Month into working remotely — a review of what worked well and what did not

Terminal Aliases are Your Friends!

Perfectly looped gif of a cat pushing a spinning ball toy. https://www.meowingtons.com/blogs/lolcats/perfect-loop-cat-gifs

My search for an Offline CMS and static site/blog builder

Best Practices in Software Testing

Font NFT exchange contract is live in the Fantom Network

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anani Oluseyi

Anani Oluseyi

Software Developer

More from Medium

Magento vendors, do you test your code for php8 compatibility at all?

The inspect tool — tips and tricks

Using a Drupal Cron job instead of an update hook

Ways to Make Web Applications From Scratch With Laravel