PHP syntax can be written anywhere in document.
Just we have to start with “<?php” and end with “?>”.
PHP statement terminate with semicolon (;).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LearnCoding</title>
</head>
<body>
<?php
// Php starts here
?>
</body>
</html>
The Echo statement is used to output text or HTML content to the browser. It can be used to display variables, strings, or a combination of both. The basic syntax for echo is:
<?php
echo "Welcome to learnCoding";
?>
Note: There are multiple alternate keywords for Output.
Keywords (e.g., echo, whitespace, if, else, if else, while), classes, functions, user-defined functions, are not case-sensitive.
<?php
// Php is not Case Sensitive
EcHo "Output using EcHo"."<br>";
echo "Output using echo"."<br>";
ECHO "Output using ECHO"."<br>";
?>
However, Variables are Case Sensitive
<?php
// But variables are Case Sensitive
$skill = "Php";
echo "My Skill is $Skill"."<br>"."<br>";
echo "My skill is $skill"."<br>";
echo "My SKILL is $SKILL"."<br>";
?>
Comment is a piece of text within the source code that is not executed by the PHP interpreter.
PHP supports both single line and double line comments.
Single-Line Comments:
Denoted by ‘//’
Anything after ‘//’ on a line is treated as a comment.
Multi-Line Comments:
Enclosed between ‘/*’ and ‘*/’
It can span multiple lines.
<?php
/* Comments
Calculate the sum of two numbers*/
$num1 = 5;
$num2 = 10;
$sum = $num1 + $num2;
// Output the result
echo "Sum of $num1 and $num2 is: $sum";
?>
Note: It is used to describe or explain any line of code, making it easier for other developers to understand the code.