PHP Tutorial


Basic PHP 7 Syntax

Author:- w3alert.com
Updated Date:-01-02-2020

PHP Syntax tutorial, this tutorial will help you to learn the very basic syntax of PHP and explain fundamentals for PHP syntax with examples.

PHP Basic Syntax

The php code or script starts with "<?php" and ends with "?>" . These tags are also know as ‘Canonical PHP tags’. You can place your php code inside these tags.

<?php
// Your PHP code goes here
?>

Note:- The default file extension for PHP files is ".php". and A PHP file basically contains HTML tags, and some PHP scripting code. One more very important thing about PHP, Any PHP statements end with a semicolon (;).

Short HTML Tags (SGML)

In PHP, the php code or script starts with "<?" and ends with "?>". This is the shortest option to write the php script or code inside these tags.

<?
// Your PHP code goes here
?>

Write first hello world program in PHP

<!DOCTYPE html>
<html>
<body>

<h1>First Hello World PHP Program</h1>

<?php
echo "Hello World!";
?>

</body>
</html>

Write first hello world program in PHP using the Short HTML Tags (SGML)

<!DOCTYPE html>
<html>
<body>

<h1>First Hello World PHP Program</h1>

<?
echo "Hello World!";
?>

</body>
</html>