PHP: ‘Hello, World!’ Tutorial

Just like with any language the first step is to begin with the very basics. The “Hello World” code has been a standard element on every programming language as it is the gateway for deeper learning.

The Code

				
					<?php
	echo 'Hello, World!';
?>
				
			

Paste this code in any .php file and run it… The result should be the display of the words “Hello World”.

So besides learning your first code, you will also learn three php elements with this example.

Echo

The “echo” statement has the function of displaying readable content in your browser. It is followed by ” or “” with the content to display within the quotes.

Semicolon

Every php statement must end with a semicolon ‘;‘. You will notice that when semicolons are not placed at the end of a php statement, the code will break and errors will arise.

Open and Close PHP

For basic tutorial instance, you need to open and close a php segment with ““. In some advanced cases, you will not need to open and close PHP within the same file but in most cases it will be.

Complete Code

Create a file called hello.php with the following code and open it on your browser.

				
					<!DOCTYPE html>
<html>
<head>
<title>Hello, World! Page</title>
</head>
<body>
<?php
	echo 'Hello, World!';
?>
</body>
</html>
				
			
Share on facebook
Share on twitter
Share on linkedin
Share on reddit
Share on email

Related Posts