Basic PHP Syntax ?

PHP content can be set in anyplace in the record. Beginning a PHP script with:

Basic PHP Syntax ?
PHP content can be set in anyplace in the record. Beginning a PHP script with:

The plain HTML output is returned to the browser after a PHP script is run on the server. Anywhere in the document, a PHP script can be inserted. A PHP script ends with ?> and begins with

<?php
// PHP code goes here
?>

PHP files have a default extension of.php. PHP scripting code and a few HTML tags are typically found in a PHP file. Here is an example of a basic PHP file with a PHP script that outputs text on a webpage using the PHP echo function:

Example
A simple .php file with both HTML code and PHP code:

<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

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

</body>
</html>

Note: All PHP statements end with a semicolon (;).

PHP Case Sensitivity

Classes, functions, user-defined functions, and PHP keywords (such as if, else, and echo) are not case-sensitive. Both echo statements in the following example are permissible:

Example
ECHO is the same as echo:

<!DOCTYPE html>
<html>
<body>

<?php
ECHO 'Hello World!<br>';
echo 'Hello World!<br>';
?>

</body>
</html>

Note: However; all variable names are case-sensitive!

Just the first statement in the example below will show the value of the $color variable! This is a result of treating $color and $COLOR as distinct variables:

Example
$COLOR is not same as $color:

<!DOCTYPE html>
<html>
<body>

<?php
$color
= "red"; echo "My car is $color<br>"; echo "My house is $COLOR"; ?>
</body> </html>

Exercise?
A PHP script starts and ends with:

  • <?
    //PHP code
    ?>

  • <?php
    //PHP code
    ?>

  • <?php
    //PHP code
    ?php>