Last Updated on
Table of Contents
No tutorial would be complete at this point without a little bit of Wikipedia research.
In terms of features, PHP is fairly limited. After all, PHP was based on C, so the syntax tends to be similar. That said, PHP does offer some core libraries that make sense for web development. For instance, PHP includes functionalities for hashing, json, xml, and glob.
Hello World in PHP
As always, let’s get down to business with an implementation of Hello World in PHP:
<?php echo "Hello, World!"; ?>
And, that’s it. In fact, we can shorten this implementation:
I’ve read that leaving the PHP tag open in the second example is the preferred method for pure PHP files. At any rate, let’s dive into the code a bit.
If we use our first implementation as an example, the first thing we’ll see is a PHP tag. The PHP tag exists because the code is actually embedded in an HTML file. In other words, the PHP tag indicates to the PHP interpreter that we have code for processing. Otherwise, the interpreter outputs the raw text.
After that, we have a bit of PHP code which allows us to write our string to the web page. In this case, the print command is echo. That might sound familiar for anyone who has done some command line work because echo is the same command used in command line scripting. More on that when we get to shell scripting.
Finally, we have the closing PHP tag. This signals to the interpreter that we are done processing PHP code. Of course, in the second example, we omit the closing tag. This is done for a variety of reasons, but it’s mainly done to eliminate extra space issues after the tag.
How to Run the Solution
As usual, we can run the solution using an online PHP interpreter. Just drop the code into the editor and hit run.
Alternatively, we have to launch up a local server, so we can view the webpage the PHP produces in our browser. From what I understand, a lot of people use XAMPP which is an all-in-one kit for PHP development.
Sample Programs in Every Language
Once again, if you enjoyed this tutorial, let me know in the comments. I’m always looking to improve these as I continue my journey.