Ever since it was created in 1995, PHP has become the most popular programming language for websites, web projects, and scripts. This is why it’s recommended that if you want to be a web developer, you should have at least a basic knowledge of PHP. You don’t need to be able to code fluently in PHP, but you shouldn’t be completely out of your depth when you encounter a php-website, either.
In this guide, we tell you everything you need to know to get started with PHP. Let’s jump right in!
Table of Contents
What is a php-website?
A “php-website” is a very loose way of referring to a website created using PHP. You can create your very own php-website using any of the larger packages on our platform, which have been specifically designed to give web developers access to our website builder’s code.
What does PHP mean?
PHP is a server-side, open source programming language that lets you create dynamic websites. Like HTML, PHP is a scripting language, which means code doesn’t need to be compiled before it can be used. Code will automatically be processed when it needs to be.
Thanks to popular CMS like WordPress, you don’t actually need to learn PHP or any other languages if you want to create dynamic sites, but if you’re interested in being a web developer, you’ll make a lot more money if you learn to code the traditional way, instead of taking shortcuts.
PHP works with versions of Apache, and you install it on top of your server software. Once you’ve installed it, you can use it by inserting PHP code into your website’s HTML.
Why is PHP so popular?
Here’s why so many developers love PHP:
- It’s the “P” in the LAMP stack (Linux, Apache, MySQL, PHP), which means it’s available on pretty much any server you can get from a web host.
- It’s not a very intense programming language, so it’s a great way to dip your toes into coding.
- It doesn’t need a special environment. All you have to do is make a .php file, combine PHP and HTML, put it on your server for rendering, and you’re good to go!
What can a php-website do?
The better question is “What can’t a php-website do?” Because this is a list of just some of the things you can do using PHP:
- Track users
- Publish entire websites using a single layout template
- Process information from web-based forms
- Serve pages that can adapt to suit different browsers and devices
- Deliver XML pages
You can do so many things with PHP that we could create a separate guide just talking about all the useful functions of PHP.
Now that you know some of the ways you can use PHP, here’s a quick guide to help you write your first PHP script:
Rules of PHP
The rules of PHP are few and easy to remember:
1. The file that contains your PHP script must end in .php. (Your file will be saved as plain text.)
2. Unless you want to find yourself staring in confusion at your own code because you worked on it months ago and don’t remember what on earth you were trying to get your script to do, use the comment tags to leave yourself notes.
- Basic PHP syntax: Here’s some basic PHP syntax to help get you started:
- Starting your code: Every piece of code you write in PHP must begin with “<?php” or, if your server is configured to handle it, “<?”.
- Ending your code: To end your code, write “?>”.
- Separating your chunks: Each separate line of code that acts as an instruction should end in a semicolon (;).
Functions
Your function should be written first, followed by the specific instruction in parentheses, then a semicolon to finish it:
print (SNOW WHITE WAS A REDHEAD. SPREAD THE WORD.);
How to write comments in PHP
To separate comments from your code, you can use one of these options:
OPTION 1: Start your notes with “//” at the beginning of each line:
<?php // This script is actually kind of fun to write. I wonder if I can use it to create a dinosaur made entirely of text ?>
OPTION 2: Surround your notes with “/*” at the beginning and “*/” at the ending:
<?php /* This script is actually kind of fun to write. I wonder if I can use it to create a dinosaur made entirely of text…No, not just any dinosaur. A tyrannosaurus rex. Nay! A tyrannosaurus TEXT */ ?>
Fun fact: PHP is not white-spacesensitive
PHP will simply ignore all the spaces and tabs in a single row. Unless there’s a semicolon, PHP will treat multiple lines as one single command. This makes things much easier for you when you’re coding, because you don’t have to worry about how many lines your instructions take up!
Wrapping up
PHP is a great programming language for beginners. Its syntax is easy to learn, and because it’s open source, there’s tons of information online for you to sink your teeth into. We hope this guide made you want to learn even more about PHP, because if you do, you’ll be joining a warm, thriving community of people who love coding just as much as you do!