A PHP script can be placed anywhere in a document and begins with <?php and ends with ?>.
|
The default file extension for PHP files is “.php”.
A typical PHP file includes HTML tags along with PHP scripting code.
Here is an example of a simple PHP file with a PHP script that uses the built-in “echo” function to display “Hello World!” on a web page:
An example of a simple .php file containing both HTML and PHP code:
<!DOCTYPE html>
?>
|
Note: PHP statements terminate with a semicolon ( ; ).
In PHP, keywords (such as if, else, while, echo, etc.), classes, functions, and user-defined functions are not case-sensitive.
In the example below, all three echo statements are equivalent and valid:
ECHO is equivalent to echo.
<!DOCTYPE html> <?php echo "Hello World!<br>"; EcHo "Hello World!<br>"; ?>
</body> |
Note: However, all variable names are case-sensitive! |
In the example below, only the first statement will display the value of the $color variable! This is because $color, $COLOR, and $coLOR are considered three distinct variables.
$COLOR is not the same as $color.
<!DOCTYPE html> <?php ?>
</body> |