PHP Tutorials – PHP Syntax

PHP Tutorials PHP Syntax

PHP scripts can be placed anywhere inside an HTML document. You can place them at the beginning of your HTML, inside the HTML tags or at the end of the HTML document.

In this tutorial we are going to write a simple script that is going to print an “Hello World!” string to the browser to demonstrate the syntax of PHP code. You can use any text editor of your choice to write and edit PHP code.

Create a new text document file and save it in your local computer htdocs folder as helloword.php . All PHP scripts must have a file extension of .php in order to executed by the server.

After creating the file open it in your text editor of choice and type in the following code:

We are going to include our PHP code in between the HTML <body> tags. PHP scripts begin with an opening tag <?php  and ends with the closing tag ?> . In between the tags you can place your php code and have them executed by the server.

We are going to use the PHP  echo ""  statement to print an ‘Hello World’  H1 heading string to the browser. You place the text to be printed to the browser in between the double or single quotes in the echo statement.

As you have noticed above, all PHP statements have to be terminated with a semicolon to mark the end of the statement. Save your file, start your web server and load the file by pointing your web browser to the url


Remember to include the file name together with the file extension in the url: in our case .php so that that server recognizes that it’s a PHP script to be executed.

If everything was done right you should the string below printed out in your browser window.

Hello World!

That is the basic PHP syntax that you would use throughout your PHP applications.

Found this article useful? Please share your thoughts below.

You might also like the article on PHP Tutorials – How to Include Comments in PHP

About the Author Geoffrey Barnes

Geoffrey is an experienced software developer and open source evangelist. When not coding he writes and talks about current technology trends, small business tips and developer productivity hacks. He is no coffee addict.

follow me on:

Leave a Comment: