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
Published 2 years ago
Updated 2 years ago

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.

egghead
egghead
~ 3 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today