PHP Syntax

Basic PHP syntax

Following is a basic PHP syntax:

A PHP code is enclosed within .
It always starts with <?php and ends with ?>.
<?php is called a opening tag and ?> is called closing tag.
<?php ?> tells PHP to start and stop interpreting the code between them.
All statements within code must end with semicolon ( ; ).
Otherwise, errors will be generated.

PHP Example

Output:

In this example we use HTML tags and PHP code.
Save this file with .PHP extension.
So to understand above code you should know HTML tags.
echo is used to print the outputs on screen in PHP.

PHP was designed to work with HTML and it can be embedded into the HTML code.

But also you can create PHP files without any html tags and that is called pure PHP file.
Also note that if you are embedding PHP within XML, XHTML you need to use the <?php ?> tags.

Ankit Wasankar

Senior Java Developer
Java 11 | Microservices | Reactjs | SQL

Help others by sharing the content!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.