Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

PHP syntax


May 10, 2021 PHP


Table of contents


PHP syntax


The PHP script executes on the server and then sends the HTML-only results back to the browser.


Basic PHP syntax

PHP scripts can be placed anywhere in the document.

The PHP script starts with .lt;?php and ends with ?::

<?php

PHP code
?>

The default file extension for PHP files is .php.

PHP files typically contain HTML tags and some PHP script code.

Below, we provide a simple example of a PHP file that outputs the text "Hello World!" to the browser.

<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

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


</body>
</html>

Run an instance . . .

Each line of code in PHP must end with a sign. A sign is a separator that distinguishes an instruction set.

With PHP, there are two basic instructions for output text in the browser: echo and print.


Comments in PHP

<! D OCTYPE html>
<html>
<body>

<?php
This is a PHP single-line comment

/*
This is
PHP multi-line
Comments
*/
?>


</body>
</html>

Run an instance . . .

Related tutorials

HTML tutorial