👨🏼‍💻 Part 1: Hello world

PHP file always starts with opening PHP tag, and ends with closing PHP tag.
In modern PHP versions, closing tags are not required.

Everything written outside the PHP tags, is parsed as regular HTML code and is printed on the website.
Each command will have to end with a semicolon, except loops and definitions of functions.

Below is a simple PHP program which will print “Hello world!” on your browser.

Simple Hello World command
<?php 
   echo "Hello world!";
?>

Alternatively, if you want your code to be more compact, you can also write it on one line like this:
<?php echo "Hello world!"; ?>

You can also write some things as part of your HTML document, and some things to parse through PHP
Hello 
<?php echo " world!"; ?>

You can use multiple echo commands to get the same result
<?php 
  echo "Hello";
  echo " world!";
?>

Independent exercise:

Using FileZilla, create a file in your server, for example “hello.php”.
Open the file, and write a code that would print some text in the browser.

Access the file, by navigating to https://yoursite.com/hello.php

The result should be something like this.

Scroll to Top