Google News
logo
PHP Program to Basic Syntax
Here is an example of a basic PHP program with syntax explanation :
Program :
<!DOCTYPE html>
<html>
<head>
	<title>My PHP Page</title>
</head>
<body>

	<?php
		// This is a comment in PHP
		$message = "Hello, World!"; // Assign a string value to a variable
		echo $message; // Print the value of the variable to the screen
	?>

</body>
</html>
Output :
Hello, World!
Explanation of the syntax :

`<!DOCTYPE html>`: This is the document type declaration for an HTML document.

`<html>`: This tag denotes the beginning of an HTML document.

`<head>`: This tag denotes the beginning of the head section of the HTML document, where meta information is usually placed.

`<title>`: This tag specifies the title of the web page.

`</head>`: This tag denotes the end of the head section.

`<body>`: This tag denotes the beginning of the body section of the HTML document, where the visible content of the web page is placed.

`<?php` and `?>`: These tags are used to delimit PHP code within an HTML document.

`// This is a comment in PHP`: This is a comment in PHP. Comments are not executed by the PHP interpreter.

`$message = "Hello, World!";`: This line of code declares a variable called `$message` and assigns it the string value "Hello, World!".

`echo $message;`: This line of code prints the value of the `$message` variable to the screen.


Note that in a PHP program, code can be embedded within HTML code by enclosing it within `<?php` and `?>` tags.