Basic Syntax in PHP
In this tutorial, we will learn the basic syntax of PHP language. We will go through the key components of a simple PHP program.
PHP Program
<?php
echo "Hello, World!";
?>
Output
Hello, World!
Basic Syntax of a PHP Program
<?php
This opening tag indicates the start of a PHP code block.echo "Hello, World!";
This line uses theecho
statement to output the string "Hello, World!" to the browser or standard output.?>
This closing tag indicates the end of a PHP code block.
Key Points to Remember
- All PHP statements must end with a semicolon (
;
). - PHP code is typically embedded within HTML using tags like
<?php
and?>
. - Comments can be added using
//
for single-line comments or/* ... */
for multi-line comments. - PHP is case-sensitive, meaning that
echo
andECHO
would be considered different.