Introduction to PHP
Table of Contents
PHP is the most popular and widely-used server-side scripting language and powers million of websites on the internet. The chances are really high that many of your favorite websites use PHP. PHP is used on the server to create interactive and dynamic websites as opposed to static never-changing pages.
PHP scripts are executed on the server and returns to the user the HTML, CSS, and JavaScript that our browsers need to render a page. Because of this, the browser never actually comes in contact with or understands PHP at all. When you access a PHP-powered website, the URL you request will trigger the server to execute one or many .php
files. These PHP files will ultimately generate HTML, CSS, and JavaScript, depending on the PHP code logic.
The logo for the PHP language.
In this Diving into PHP class, learn everything from the syntax for PHP, handling form data, sending emails, using cookies, making database calls, and much more. But first, make sure you meet the prerequisites for this class.
Prerequisites
- Intermediate knowledge of HTML. Luckily for you, we have a great class on that
- An environment to run PHP. This can be Internet Information Services (IIS), Apache, or your own web server
With that being said, let's dive into PHP!
Selecting a Text Editor
Since PHP is ultimately just plain text, you can use any text editor you want for this class. With that being said, we suggest using Visual Studio Code. It will support the operating system you're running on, and its syntax highlighting makes writing PHP fun!
Of course, feel free to use whatever text editor you might already be using.
Visual Studio Code
Hello World
The easiest way to get started with PHP is to just do a Hello World
example. Create a new file called index.php
. The .php
file extension lets the server know that this is a PHP file and that it should run any code that happens to be in the file. Inside the file, and enter this:
PHP<!DOCTYPE html>
<html>
<head>
<title>Diving into PHP</title>
</head>
<body>
<?php
// Display the text 'Hello World'
echo('Hello World');
?>
</body>
</html>
Save the file and access it in your browser. As you might expect, you get an otherwise blank page with the text Hello World
in it. If you were able to see:
Hello World in PHP
You have everything you need to continue on with this class on PHP!
That feeling when you're ready to start learning PHP
- Getting Started with TypeScript
- How to Install Node on Windows, macOS and Linux
- Managing PHP Dependencies with Composer
- How to Serve Static Files with Nginx and Docker
- How to Set Up Cron Jobs in Linux
- How to deploy a PHP app using Docker
- Getting Started with Deno
- How to deploy an Express app using Docker
- How to Scrape the Web using Node.js and Puppeteer
- Getting Started with Handlebars.js
- Using Push.js to Display Web Browser Notifications
- Setting Up a Local Web Server using Node.js