The First PHP Script You'll Ever Write! (Probably)

Published on June 15, 2018 under code

Over the years of writing applications and the like I've always followed my heart with the languages I've really connected with - the primary one being PHP. I've also noticed a lot of people out there aren't too familiar with writing something as simple as a basic, "Hello World!" script via PHP.

Echo is a very simple function - what you're doing is directing the output of one or more strings.

<!DOCTYPE html>
<html>
    <head>
        <title>The first PHP script you'll ever write!</title>
    </head>
    
   	<body>
        <?php
            echo "Hello world!";
        ?>
    </body>
    
</html>

You could also write it a bit differently by using a variable.

<!DOCTYPE html>
<html>
    <head>
        <title>The first PHP script you'll ever write!</title>
    </head>
    
   	<body>
        <?php
            $hello = "Hello World!";
            echo $hello;
        ?>
    </body>
    
</html>

Or we could go even beyond that and use multiple variables. This is actually something you're very likely to do within various scopes.

<!DOCTYPE html>
<html>
    <head>
        <title>The first PHP script you'll ever write!</title>
    </head>
    
   	<body>
        <?php
            $hello = "Hello World!";
            $hay = "How are you?";
            echo $hello . " " . $hay;
        ?>
    </body>
    
</html>

As I stated above the previous example, you're likely to be using multiple variables when it comes to your own coding projects using PHP - my best recommendation would be, if you really want to learn PHP, download the official documentation and read it like the bible.

PHP Documentation: http://php.net/docs.php


End.

Jason Michael Author

A developer/musician from Boston, Massachusetts just trying to find his place in the world through code, keys, and various other bizarre mediums.

Fractal Continuum © 2018
Proudly hosted by Digital Ocean