What is PHP?

PHP (Hypertext Preprocessor, or originally Personal Home Page) is an open-source, server-side scripting language used to develop static and dynamic websites and web applications. It's one of the oldest scripting languages in the business and is used for over 78% of websites that power the internet today.

How PHP Works

PHP is a scripting language, not a programming language, meaning it creates a set of programming instructions that are interpreted and performed at runtime rather than requiring compilation beforehand. This helps enhance the performance of websites and web applications written in PHP.

PHP works behind the scenes with the web server, taking the written script and converting it to a set of programming instructions that it understands, and returns the results in HTML format to the web browser for display and user interaction.

History of PHP

PHP development began in early 1994 when programmer Rasmus Lerdorf created many Common Gateway Interface (CGI) programs in C, resulting in extensions to work with web forms and communicate with databases that he later dubbed "Personal Home Page/Forms Interpreter", or PHP/FI. Early PHP was not intended to be a new language but grew organically quickly.

Zeev Suraski and Andi Gutmans rewrote the parser in 1997 which spawned the creation of PHP 3 and launched in June 1998. PHP 4 was created and powered by the Zend Engine and was released in May 2000. Followed a few years later, PHP 5, powered by the Zend Engine II, improved support for object-oriented programming, as well improved database support and included many performance enhancements.

From there, PHP grew much larger into what we know today. PHP is the most used server-side language powering almost 8 out of 10 websites worldwide and some of the most popular social media outlets and content management systems, including Facebook, WordPress, and Joomla.

Why Use PHP?

There are many scripting languages out there growing in popularity, so what makes PHP stand out above them all? Well, to start:

  • PHP is well-known, so it's well documented and has a large community behind it. It's incredibly easy to find solutions, examples, and help when needed.
  • PHP is easy to learn. The learning curve is a lot shorter compared to other languages like ASP or JSP. You can install PHP and get going pretty quickly which I'll illustrate here shortly.
  • Many web hosting companies use PHP. Pretty much every web hosting company offers PHP to some end, which helps keep hosting costs down and options open.
  • PHP is cross-platform. You can deploy your PHP applications on a variety of operating systems including Windows, Linux, and Mac OS.
  • PHP supports many database management systems. MySQL support is built in with the option of expanding to other database management systems such as SQL Server, Oracle, Postgres, and more.
  • PHP is open source and free. Enough said.

Writing Your First PHP Script

When writing code in PHP, all functions and outputs must be nested in PHP tags like the below example. Otherwise, they will be output to the screen as plain text:

<?php ... ?>

We can use the echo statement to output the text "Hello There!" to the screen:

<?php
echo "Hello There!";
?>

// output:
// Hello There!

Notice that the end of the echo statement contains a semicolon (;). This is required for most statements in PHP and is best practice to include them where ever possible to prevent script errors.

Conclusion

As you can see, it doesn't take much to get started with your first PHP application. In the end, to each their own regarding whichever scripting language he or she decides to code in. While all of the server-side languages out there have their pros and cons, it comes down to personal preference and overall goals for the projects you're working on.

PHP has been a proven solution for websites and web applications of all shapes and sizes, so it's one I would highly recommend considering for your next project.

Get started with PHP by visiting php.net.  Or hop right into the setup by visiting their downloads page.