PHP Syntax
A PHP script starts with <?php and ends with ?>. Anything outside these tags is treated as plain HTML and sent directly to the browser. Each PHP statement ends with a semicolon, just like many other C-style languages.
PHP is loosely typed, meaning you don't need to declare a variable's type in advance, and PHP is mostly case-insensitive for keywords and function names, but variable names are case-sensitive.
<?php
// PHP code here
?>PHP tags
The standard way to write PHP is <?php ... ?>. You can embed multiple PHP blocks inside a single HTML file, switching freely between HTML and PHP.
Case sensitivity
Keywords like if, echo and function are case-insensitive, but variables such as $Name and $name are treated as two completely different variables.
<?php
$x = 5;
$y = 10;
echo $x + $y;
?>15PHP code between the tags is executed, and the result is sent to the browser.
<!DOCTYPE html>
<html>
<body>
<?php
echo "This is inside HTML!";
?>
</body>
</html>This is inside HTML!PHP can be embedded anywhere inside a regular HTML document.
Key points
- PHP code is wrapped in <?php ... ?> tags.
- Each statement ends with a semicolon.
- PHP variables are case-sensitive, but keywords are not.
- PHP can be mixed freely with HTML markup.
