Ghost
Platinum Coder
I want to share this easy beginner PHP tutorial for how to code Hello World in PHP! It is one of the easiest ways to learn a new programming language because it covers how to start your code block in the PHP file and show text on the page. You can read my full beginner PHP Hello World tutorial for all the different types of PHP programming, code, and functions you can learn just from a basic hello world guide. Using echo is the easiest way, but you can also use PHP's print statement.
Step 1) Create a PHP file
A PHP file is simply anything ending with the .php extension. Of course, you must have PHP enabled and set up correctly on your home computer or your server.
For my example, I will create 'HelloWorld.php' as my PHP script.
Step 2) PHP Script Code
You must make sure to start your code with the PHP open tag <?php
Similarly, you must end your PHP script with the end tag ?>
You can now write PHP code inside of the open and close tags.
How to code a PHP Hello World script:
Another way to say Hello World in PHP:
HTML with PHP is super easy! In fact, this was one main reason PHP was originally created. PHP Echo displays HTML on the page just as you would expect:
As you can see, you can easily echo a string of text in the PHP script. HTML is allowed, so feel free to play around with <strong>bold text</strong>, or other formatted text like <h1>header text</h1>! PHP echo is very easy to use because it's short, sweet, and you do not have to declare the type of variable/data being output or the number of characters like you may in other more advanced languages.
You can even use variables in the echo statement...
Step 1) Create a PHP file
A PHP file is simply anything ending with the .php extension. Of course, you must have PHP enabled and set up correctly on your home computer or your server.
For my example, I will create 'HelloWorld.php' as my PHP script.
Step 2) PHP Script Code
You must make sure to start your code with the PHP open tag <?php
Similarly, you must end your PHP script with the end tag ?>
You can now write PHP code inside of the open and close tags.
How to code a PHP Hello World script:
PHP:
<?Php
echo "Hello World";
?>
Another way to say Hello World in PHP:
PHP:
<?Php
echo("Hello World");
?>
HTML with PHP is super easy! In fact, this was one main reason PHP was originally created. PHP Echo displays HTML on the page just as you would expect:
PHP:
<?Php
echo "<h1>How to Code Hello World in PHP</h1>";
echo "<p>As you will see, your PHP script can echo HTML and it will work as expected.</p>";
?>
You can even use variables in the echo statement...
PHP:
<?Php
$person = "Ghost";
$words = "Hello World!";
echo "$person says $words";
// page says: Ghost says Hello World!
?>