PHP Simple Syntax

Basically, a PHP file is a text file with the extension .php which consists of:

  • Text
  • HTML tags
  • PHP Scripts

To work with PHP you need to know HTML but we are going to generate dynamic web pages with PHP. PHP is not difficult! On the contrary, PHP is often very similar to plain English.

Let's get started with your first PHP page.

PHP Hello World! Example

Start by making an simple HTML document, but name the file index.php and save it in the root of the site:

The HTML code should look like this:

Now, we need to tell the server when the PHP will start and end. In PHP scripting language you use the tags <?php (start) and ?> (end) to mark the start and end of the PHP codes that the server must execute.

Now try to add the following simple code snippet to your HTML code

But it will be interesting when you look at the HTML code in the browser (by selecting "view source"):

PHP Date and Time Example

Let's make the server write something else. We could, for example, ask it to display the current date and time:

Now the corresponding HTML code looks like: