Skip to main content
TopMiniSite

Back to all posts

How to Write A Simple "Hello World" Script In PHP?

Published on
3 min read
How to Write A Simple "Hello World" Script In PHP? image

Best PHP Guidebooks to Buy in October 2025

1 PHP & MySQL: Server-side Web Development

PHP & MySQL: Server-side Web Development

BUY & SAVE
$29.21 $45.00
Save 35%
PHP & MySQL: Server-side Web Development
2 Practical Marketing Research: A Guidebook for Marketing Insights

Practical Marketing Research: A Guidebook for Marketing Insights

BUY & SAVE
$69.00
Practical Marketing Research: A Guidebook for Marketing Insights
3 PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide

PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide

BUY & SAVE
$49.97
PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
4 PHP and MySQL Web Development (Developer's Library)

PHP and MySQL Web Development (Developer's Library)

BUY & SAVE
$41.99 $59.99
Save 30%
PHP and MySQL Web Development (Developer's Library)
5 Head First PHP & MySQL: A Brain-Friendly Guide

Head First PHP & MySQL: A Brain-Friendly Guide

BUY & SAVE
$17.43 $54.99
Save 68%
Head First PHP & MySQL: A Brain-Friendly Guide
6 Murach's PHP and MySQL (3rd Edition)

Murach's PHP and MySQL (3rd Edition)

BUY & SAVE
$43.29 $57.50
Save 25%
Murach's PHP and MySQL (3rd Edition)
7 Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)

Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)

BUY & SAVE
$30.15 $49.99
Save 40%
Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)
8 PHP & MySQL For Dummies, 4th Edition

PHP & MySQL For Dummies, 4th Edition

BUY & SAVE
$9.46 $29.99
Save 68%
PHP & MySQL For Dummies, 4th Edition
9 PHP for the Web: Visual QuickStart Guide

PHP for the Web: Visual QuickStart Guide

BUY & SAVE
$34.90 $44.99
Save 22%
PHP for the Web: Visual QuickStart Guide
+
ONE MORE?

In PHP, writing a simple "Hello World" script is quite easy. Here is an example of how you can do it:

Let's break it down:

  • are the opening and closing tags of PHP code. All PHP code should be written between these tags.
  • echo is a PHP function used to output text or variables. Here, it is used to output the string "Hello World!".
  • The semicolon ; at the end of the line indicates the end of the statement.

You can save this script with a .php extension (e.g., helloworld.php) and then run it on a PHP-supported server. When executed, it will display "Hello World!" as the output on the webpage or command line interface, depending on where you run the script.

This simple example serves as a starting point for understanding PHP scripting and can be expanded upon to perform more complex tasks.

What is the purpose of a semicolon in PHP?

In PHP, a semicolon (;) is used as a statement terminator. It is used to separate individual instructions or statements. When writing PHP code, each statement should end with a semicolon to indicate the end of that statement. It helps the PHP interpreter identify the boundaries of expressions and separate them.

How to define a variable in PHP?

To define a variable in PHP, you can use the $ symbol followed by the variable name, and then assign a value to it using the = operator. Here's an example:

$myVariable = "Hello, World!";

In this example, we have defined a variable named $myVariable and assigned the value "Hello, World!" to it.

How to save a PHP file?

To save a PHP file, you can follow these steps:

  1. Open a text editor or an Integrated Development Environment (IDE) that supports PHP development, such as Notepad++, Sublime Text, Visual Studio Code, or PHPStorm.
  2. Create a new file by selecting "New" or "File -> New" from the menu bar, or by using the shortcut Ctrl + N (Windows) or Cmd + N (Mac).
  3. Write your PHP code in the editor. For example, you can start with the standard opening tag
  4. Once you have finished writing your PHP code, save the file by selecting "Save" or "File -> Save" from the menu bar, or using the shortcut Ctrl + S (Windows) or Cmd + S (Mac).
  5. Choose a name for your file and make sure to give it the .php extension. For example, you can save the file as example.php.
  6. Select the location where you want to save the file, such as your local computer or a web server directory.
  7. Click "Save" to save the PHP file.

Now, your PHP file is saved and ready to be executed or used in your web development projects.