What Is PHP? (+How to Use It to Code Your Website)

Mara Calvello
Mara Calvello  |  March 26, 2019

If you’ve ever thought about learning a new language, you know that it takes time and discipline.

While you may be inclined to teach yourself Italian, French, or Mandarin, there are others that may spark your interest in the form of coding languages.

If you have recently decided that it’s time to learn to code so you can further educate yourself in the realm of website building, tackling PHP is bound to be on your list of coding languages you’ll want to get familiar with.

Whether you’re a developer, software engineer, or just someone who is interested in dabbling in the world of website building, let’s get started breaking down all of what PHP can do.

Want to learn something specific about PHP? Jump ahead in this article to:

What is PHP?

With over 20 million websites and applications on the internet that are developed using PHP, it is one of the most common and frequently used coding languages.

PHP is used in conjunction with HTML. While PHP is executed on the server, the plain HTML result is then sent back to the browser for the user to see. In addition to being embedded into HTML, it can also be combined with web template systems, web content management systems, and web frameworks.

Related: PHP once stood for Personal Home Page.

What is PHP used for?

PHP is ideal for creating complex web pages, as this scripting language can collect form data, generate dynamic page content, enhance web pages, create usernames and passwords, and send and receive cookies. There are five main forms of websites that use PHP in its code.

  1. E-commerce websites with heavy amounts of traffic (like Amazon)
  2. Secure websites used for payment (like PayPal)
  3. Email web hosting platforms (like Gmail)
  4. Database management and social platforms (like Facebook and Wikipedia)
  5. Content Management Systems (like WordPress
Common Sites Using PHP


When it comes to this server-side scripting language, the possibilities are endless. So no matter what website you're building, or the purpose of your website, it’s in your best interest to learn how to best utilize PHP.

PHP syntax

All PHP syntax starts with <?php and ends with ?>. Each individual line is closed out using a semicolon (;). There are many components that go into PHP syntax that are used to code the server side of a website. Below are some common pieces to the line of code.

Variables

Variable names are case sensitive and start with the dollar sign ($) followed by the name of the variable. There are six main types of variables:

  1. String: a sequence of characters
  2. Integer: whole numbers without a decimal point
  3. Doubles: numbers with a decimal point
  4. Boolean: a statement that is either true or false
  5. Array: Stores multiple values in one single variable
  6. Null Value: a special type with one value, NULL
Tip: Think of variables as containers for storing data!

When you assign a text value to a variable, use quotes around the name. Since variables are case sensitive, the variables $name and $Name are two different variables.

<?php
$name = “Mara”;
$Name = “Melissa”;
?>

Constants

In PHP, constants are also case sensitive and always begin with an uppercase letter or underscore, not a letter. Constants are written using the define ( ) function. 

Valid and Invalid Constant Names in PHP 

The above example of an invalid constant is invalid because constants cannot start with a number.

Constants are different than variables in the sense that constants are not defined by a simple assignment, as they must be written and accessed anywhere using define ( ). Once they are defined, they cannot be changed or undefined. Choose wisely.

Comments

Like other coding languages, comments are not executed within the program, as they are only meant to be read by others writing the code.

Comments are written using two forward slashes (//).

<?php
// these are the names of two different people
$name = “Mara”;
$Name = “Melissa”;
?>

Related: Learn the difference between PHP and Python - which is better?

Be dynamic and interactive

Take your website to the next level when you execute PHP in with your HTML code. I know it can seem like a lot, but learning PHP and other coding languages will ensure that your website stands out from all the rest. It’s not used in over 20 million websites for nothing!

Interested in learning other coding languages? Check out the ins and outs of CSS and JavaScript! If you're a coding beginner, take a peak at our tips for coding websites!

Everything you need to build a website, FREE.    Get my 50 resources →

Mara Calvello
Author

Mara Calvello

Mara is a Senior Content Marketing Specialist at G2. In her spare time, she's typically at the gym polishing off a run, reading a book from her overcrowded bookshelf, or right in the middle of a Netflix binge. Obsessions include the Chicago Cubs, Harry Potter, and all of the Italian food imaginable.