What is the PHP Programming Language? Why Should I Use PHP?
A basic introduction for beginners
Search for a command to run...
A basic introduction for beginners
No comments yet. Be the first to comment.
After a few days of using the 512GB MacBook Neo with TouchID, here are my impressions after some heavy, real-world use. I'll disclaim this review by saying that I consider myself a power user; on my m

2024 was a strange year for me that was a mix of trying new things, accomplishing the best work of my career, and stark transitions into unexplored territory. I think it's important to take a moment every once in a while to step back and look at one'...

What I've Been Up To Four Months Into Freelancing

Leaving My Job with No Plan — My New Career as a Freelancer

With a few glasses of wine in me and some nostalgia-fueled synthwave playing, I found myself reflecting on my past, and my history with computers. I got to thinking of my childhood, and more specifically, my personal history with computers. I love te...

PHP is a popular programming language that runs on servers and often is used to generate the HTML code sent to your browser. It is a scripting language, so it doesn’t have to be compiled, and it is generally considered an easy programming language to learn and use.
Originally created in 1994, PHP is now on version 8.1 and has evolved substantially since that time. PHP powers a large portion of the web, and this is the language used to make the incredibly popular WordPress blogging and content management system.
PHP code starts with a <?php tag to specify that the following code should be interpreted as PHP. To end a section of PHP code, use ?>. The end tag is only required if you need to write code after that is not interpreted as PHP, such as some HTML.
To write a line comment that is not interpreted, begin a line with //. This type of comment ends at the end of the line.
If you want to write a comment that spans multiple lines, you can begin a comment with /* and end with */.
Variables in PHP begin with a dollar sign like $foo.
Because PHP is loosely typed you do not need to specify what kind of variable it is (like an integer or string) like in some other languages.
Each statement (typically a single line of code) must end with a semicolon ;.
The following assignment statement sets the variable foo to 1 and must end with a semicolon, or else there will be an error.
$foo = 1;
<?php
$message = "Hello World!";
?>
<html>
<body>
<?php
// The ‘echo’ statement will output the value of the variable.
echo $message;
?>
</body>
</html>
The above will print “Hello World!” into a simple web page. This is how easy it is to use a little PHP in a web page.
To create a web page, you simply have to write some HTML code into a text file using a text editor like notepad, or better, a programmer’s editor (also known as an Integrated Development environment, or IDE) like the excellent and free Visual Studio Code. You can then open the webpage in a browser like Google Chrome.
PHP is written in the same way but opening the code in a browser will not interpret the PHP code. Why not?
This is because the code must be interpreted by the PHP interpreter that must be installed on the computer or server where the code lives. If you wish to try writing a program of any complexity, you probably want to install PHP on your computer so you can easily do this, but just to play around and try writing a few lines of code, you can try a PHP playground like Teh Playground. (Yes, spelled that way).
Although PHP is incredibly popular, it is not exactly the new hotness. Languages like Python, JavaScript (via NodeJS), C# are also very popular today and are popular amongst many people learning to program. Despite this, many of the most heavily visited websites on the Internet use PHP on their backend, including Facebook, Etsy, Wikipedia, and the millions of WordPress websites out there. Many companies have a lot of old and new code written in PHP.
Consequently, if you are looking to become a backend or full-stack web developer, PHP is an excellent language to know.
Additionally, PHP is also a very actively maintained language that gets continually better. It has an excellent ecosystem of packages available (via packagist.org) that you can easily use to add functionality to a project with the Composer package manager, and a robust community of developers who are interested in helping each other learn and solve problems.
I hope this brief introduction to the PHP programming language has been informative for you. Please let me know in the comments if you have any questions or would like clarification on any of the points in this post!