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 July 2026

1 PHP & MySQL: Server-side Web Development

PHP & MySQL: Server-side Web Development

BUY & SAVE
$28.72 $45.00
Save 36%
PHP & MySQL: Server-side Web Development
2 Beginning PHP and MySQL Development: Code Your Own Dynamic Website Today

Beginning PHP and MySQL Development: Code Your Own Dynamic Website Today

BUY & SAVE
$0.99 $15.12
Save 93%
Beginning PHP and MySQL Development: Code Your Own Dynamic Website Today
3 Head First PHP & MySQL: A Brain-Friendly Guide

Head First PHP & MySQL: A Brain-Friendly Guide

BUY & SAVE
$13.78 $54.99
Save 75%
Head First PHP & MySQL: A Brain-Friendly Guide
4 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
5 PHP and MySQL in easy steps

PHP and MySQL in easy steps

BUY & SAVE
$7.23 $14.99
Save 52%
PHP and MySQL in easy steps
6 PHP and MySQL Web Development (Developer's Library)

PHP and MySQL Web Development (Developer's Library)

BUY & SAVE
$30.00 $59.99
Save 50%
PHP and MySQL Web Development (Developer's Library)
7 Murach's PHP and MySQL (3rd Edition)

Murach's PHP and MySQL (3rd Edition)

BUY & SAVE
$48.15 $57.50
Save 16%
Murach's PHP and MySQL (3rd Edition)
8 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
$25.30 $49.99
Save 49%
Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)
9 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.78 $49.99
Save 64%
PHP, MySQL, & JavaScript All-in-One For Dummies (For Dummies (Computer/Tech))
+
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.