The University of Texas at Austin- What Starts Here Changes the World
Services Navigation

Example 1 - Hello World in PHP

Following a long tradition of introductory programming and scripting tutorials, our first example will print "Hello World" in the browser window.

<TITLE> Hello World in PHP </TITLE>
// Hello world in PHP
 print("Hello World");

The PHP statement:

<? print("Hello World"); ?>

displays the message "Hello World" in the browser window. As was mentioned earlier, PHP statements are embedded into HTML documents and they appear between <? and ?> symbols.

The PHP print function displays the value or string within parentheses in the browser window.

Several important things to note about PHP scripts:

  • PHP is case sensitive, print is different from PRINT
  • PHP statements appear between <? ?>
  • PHP statements end with a semi-colon
  • You can include comments in your PHP code by beginning the line or lines with // characters
  • Your PHP files should have a .php extension rather than a .html extension. If scripts have a .html extension the server will not know that they are PHP files and will not parse and execute the PHP commands.

Test Example 1

View PHP Source Code


  Updated 2005 August 1
  Comments to