What is PHP? Your Most Common Questions, Answered
PHP is your friendly server-side scripting language. But what on earth does that mean — what is PHP? In this article, we’ll introduce you to the different languages of the web, how they fit into the flow of information between clients (your computer or mobile device) and servers (the physical machine that ‘serves’ up the website data), and how PHP is a heavy lifter behind the scenes.
The building blocks of the web
If you are new to web development, then getting down the basics of HTML, CSS, and JavaScript is the right move before you enter the world of PHP. These are the basics of client-side (or browser-based) elements of the web.
Last Updated April 2022
Build a Content Management System from Scratch with PHP and MySQL | By Tim Buchalka’s Learn Programming Academy, Dave Hollingworth
Explore CourseHow does PHP work?
PHP, which stands for PHP: Hypertext Preprocessor, is a server-side (aka back-end) scripting language based originally on C.
Within internet operations, a client machine, generally through a browser, will make a request to a server somewhere else in the world to view an HTML and/or PHP document.
PHP is code designed to execute on the server, rather than delivering to the browser to execute, which is known as browser-side execution.
Within this machine setup, you have a web server, generally an Apache server that supports all operating systems, such as Windows, Mac, Unix, etc. The Apache server grabs the file requested from the client (through the browser, on the other side of the world), and if there is PHP code within the file, executes it (usually through operations on a database such as MySQL or MariaDB), then returns the result to the client.
This means you can create dynamic or static page content; do file operations such as reading, writing to, and deleting on the server; capture form content from pages and store it either in files or on a database — it can even be used for encryption!
Because PHP is executed on the server, it outputs HTML to return to the browser.
What is PHP? Facts and figures to know
Now that we know high-level how PHP works, let’s break down some helpful facts and figures:
Original release date: June 1995
Original creator: Rasmus Lerdorf
Mascot: elePHPant
Current version: PHP7.4 (released November 28, 2019)
Most popular PHP editor: PHPStorm or Visual Studio Code for a multi-purpose editor
Most popular PHP frameworks: Laravel and Symfony
File extension: .php
Current number of websites running PHP: Usage statistics from W3 Techs show that 78.8% of all known websites use PHP.
Why do developers use PHP?
As we dive further into everything you need to know about PHP, let’s take a look at what makes it such a useful tool for developers.
It’s open-source
Like many programming languages these days, PHP is open-source, which means that it is free for developers to use and modify. Because it’s also a very mature language (at over 15 years old), with ongoing community updates, that also means it’s very stable.
It’s everywhere
Take a look in the back-end (again, that means the server side!) of any website or web app and you’re likely to find PHP code. PHP is cross-platform and goes anywhere including across all hosting environments, plus it’s simple to install and configure. The popularity of PHP means that many legacy websites run with PHP and are still built with it. Even better, there’s a wealth of knowledge online about PHP development.
It’s built for the web
Unlike other languages, PHP was designed specifically for the web. While it can be used as a general-purpose scripting language, that’s not its key purpose. In fact, its creator originally developed it so he could perform cool actions with forms and use a database for his personal home pages. There are languages that perform similar functions, such as Ruby; but if you want precision for the web, PHP is the better choice.
Web hosting servers already support PHP
Rather than configuring web hosting servers for a particular language, almost all host servers come ready to run PHP.
What else can PHP do?
PHP can be used in command-line scripting or in client-side operations. Due to its high portability, PHP can be inserted as a PHP script into software projects of different languages. PHP isn’t just for dynamic server-side programming, even though this is its most common use case.
How do I write a PHP file?
To write a PHP file, start with a PHP editor like PHPStorm or Visual Studio Code You may also use a general text editor, such as Notepad, although code editors are far superior. Why? Code editors use a PHP linter, a tool that helps to find errors and bugs in your code. This error checking mechanism is great for beginners so that you don’t get frustrated trying to spot where you went wrong in your code.
What are the data types in PHP?
PHP supports 8 data types, which are used to construct variables. These data types include:
- Integer
- Starting from 0
- Positive or negative
- No decimal point
- In decimal, hexadecimal, or octal notation
- Range – e.g. 32 or 64 bit – depends on the architecture
- Floating point number
- Fractional – always with a decimal point, or exponential
- Positive or negative
- Boolean
- With a value of TRUE or FALSE
- String
- One or more characters
- Array
- A collection of key/value pairs, where the key is the index in the array
- Keys can be integers or strings
- Value may be any other data type
- Object
- Contains data and associated processing methods
- Allows us to do Object-Oriented programming, even though PHP is a scripting language
- NULL
- Only equal to NULL – undefined
- Resource
- Technically, a PHP Resource isn’t an actual data type. Rather, it stores a reference to an external resource such as a database call.
What are PHP tags?
PHP tags are the notations that inform a document that the code within the tags is PHP and should be interpreted as such. PHP uses the start tag <?php and the end tag ?>. This means that PHP can be embedded in all sorts of different documents, although, most commonly, it’s embedded into a PHP file or an HTML document. This is similar to HTML start tags <html> and </html>.
How do I create PHP Hello World?
If you are creating a .php file, then you use the tags learned above to write:
<?php
echo ‘Hello, World!’;
?>
This will output the string Hello World!
Is PHP easy to learn?
Yes! Compared to other languages used for server-side scripting, such as ASP.NET, PHP is relatively easy to learn.
Which is the best database to use with PHP?
PHP comes with native support for MySQL, however, you can use it with other databases too, like Postgres, SQL Server, and Oracle Database.
Do you need to know PHP to do WordPress development?
PHP is an integral part of developing custom themes and plugins for WordPress sites. So, while you can create basic WordPress sites without knowing PHP, if you want to truly do WordPress development, then knowing PHP programming is essential.
How can you learn PHP development?
There are plenty of resources online that you can use to learn PHP. Everyone has a slightly different learning style and preference of materials, so don’t be discouraged if you try one course and you find it just not the right fit for you — try again and you might find something that will better suit your learning style.
Here are some courses to explore:
- PHP for Beginners – This course does exactly what it says on the label – introduces you to PHP programming with zero prior knowledge required
- PHP for Beginners – Become a PHP Master – CMS Project – This course teaches you PHP by building a Content Management System (CMS). Example CMSs are WordPress and Drupal.
- PHP OOP: Object-Oriented Programming for beginners + Project – Learn the fundamentals of object-oriented programming (OOP) once you have the basics of PHP down.
- PHP with Laravel for beginners – Become a Master in Laravel – Learn the Laravel framework combined with PHP to start making more complex applications.
- The Complete Web Developer Course 2.0 – Ideal for new web developers wanting a taste of many languages, try this full-stack web development course that includes HTML, CSS, JavaScript, jQuery, PHP, MySQL, and more.
Recommended Articles
Top courses in Development
Empower your team. Lead the industry.
Get a subscription to a library of online courses and digital learning tools for your organization with Udemy for Business.