PHP is a programming language that runs on a web server. When someone opens a page, the server runs your PHP code, and the result is sent to the browser as normal HTML.
Think of a restaurant. The browser is the customer, and the server is the kitchen. The customer never sees how the food is cooked. They only get the finished plate. PHP is the cook in the kitchen.
A first look
This is a complete PHP file. It prints one line of text.
<?php
echo "Hello from PHP!";
Hello from PHP!
The <?php tag tells the server that PHP code starts here. echo prints text. The browser would receive only Hello from PHP!. It never receives the PHP code.
Why PHP exists
Plain HTML is the same for every visitor. Real websites are not. A shop shows your cart, a blog shows the newest posts, and a bank shows your balance. That content changes, so something has to build the page each time. PHP was made for exactly that job.
PHP stands for PHP: Hypertext Preprocessor. The name is a joke inside a name (the first P stands for PHP itself), and you do not need to remember it.
Where you meet PHP
- WordPress is written in PHP. So are WooCommerce, Drupal and Joomla.
- Laravel and Symfony are popular PHP frameworks for building applications.
- Large websites, including Wikipedia (through MediaWiki), run on PHP.
Learning plain PHP first makes all of these easier to understand later.
You can run PHP examples on your own computer
Exercise: say hello
Look at the example above. Which part is PHP code, and which part would the visitor actually see in the browser?
Show the answer
All three lines are PHP code. The visitor sees only the text Hello from PHP!, because the server runs the code and sends back just its output.