1. 4
    Create a “Hello world!” PHP script
    2m 1s

Create a “Hello world!” PHP script

Mark Shust
InstructorMark Shust
Share this video with your friends

Social Share Links

Send Tweet

What's a tutorial without a hello world lesson? Let's learn about open and closing PHP brackets, and the "echo" language construct, which is perhaps the most-used construct in the language.

Instructor: [0:00] It's finally time for our Hello World script.

[0:03] First, our PHP web server expects to receive a file named either index.html or index.php. Since .html files cannot parse PHP, we will need to use this php extension instead. Let's go ahead and create a new file within our project named index.php.

[0:27] Wherever we wish to write PHP code, we must use an open PHP tag. This is created with an open bracket or less than sign, followed by a question mark, and then PHP. There can't be any spaces between the characters, it has to all be together.

[0:46] Now that we've created a PHP tag, we can call any language construct or built-in function of PHP. A language construct is just a fancy phrase for something that makes up the base of the PHP language. Probably the most commonly used language construct is echo, which outputs data. Let's type echo, followed by a open and close parentheses.

[1:11] Within the parentheses, we can pass in any data we'd like output to the screen. This data we pass in is called an expression, and it is evaluated at the time the PHP script is executed. Let's just pass in a string, which is always enclosed within quotes, and we could type any characters within these two single quotes. Let's type 'Hello World.'

[1:36] Finally, we can close up this PHP tag by leaving a space, and then typing another question mark, followed by an open bracket or greater than sign. This tells the PHP interpreter that we no longer have PHP code executed after this closing bracket.

[1:53] Let's save this file. Go ahead and refresh our page, and we will see our Hello World message.