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 November 2025

1 PHP & MySQL: Server-side Web Development

PHP & MySQL: Server-side Web Development

BUY & SAVE
$29.17 $45.00
Save 35%
PHP & MySQL: Server-side Web Development
2 PHP & MySQL For Dummies, 4th Edition

PHP & MySQL For Dummies, 4th Edition

BUY & SAVE
$15.21 $29.99
Save 49%
PHP & MySQL For Dummies, 4th Edition
3 PHP, MySQL, & JavaScript All-in-One For Dummies (For Dummies (Computer/Tech))

PHP, MySQL, & JavaScript All-in-One For Dummies (For Dummies (Computer/Tech))

BUY & SAVE
$17.65 $49.99
Save 65%
PHP, MySQL, & JavaScript All-in-One For Dummies (For Dummies (Computer/Tech))
4 PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide

PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide

BUY & SAVE
$47.99
PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
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
$51.71 $57.50
Save 10%
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 in easy steps: Covers MySQL 8.0

PHP & MySQL in easy steps: Covers MySQL 8.0

BUY & SAVE
$14.17 $15.99
Save 11%
PHP & MySQL in easy steps: Covers MySQL 8.0
9 PHP Programming with MySQL Database Connectivity For Beginners: Answers all your Questions Step-by-Step

PHP Programming with MySQL Database Connectivity For Beginners: Answers all your Questions Step-by-Step

BUY & SAVE
$0.99
PHP Programming with MySQL Database Connectivity For Beginners: Answers all your Questions Step-by-Step
+
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.