A PHP script starts with the <?php and ends with the ?> tag.
<?php
// Some code to be executed
echo "Hello, world!";
?>
Every PHP statement end with a semicolon (;) — this tells the PHP engine that the end of the current statement has been ended.
Use PHP within HTML
PHP files are plain text files with .php extension. Inside a PHP file, you can write HTML as you do in regular HTML pages as well as embed PHP codes for server-side execution.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Use PHP within HTML</title>
</head>
<body>
<h1>
<?php echo "Hello, world!"; ?>
</h1>
</body>
</html>
PHP Comments
PHP supports single-line comments and multi-line comments. To write a single-line comment, slashes (//), or a pound sign (#). multi-line comments. / * * /
#example.php
<?php
// This is a single line comment
# This is also a single line comment
echo "Hello, world!";
/*
This is a multiple line comment
* that is more than one line
*/
echo "Hello, world!";
?>