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 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:



My first PHP page




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:








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:








Exercise?
A PHP script starts and ends with:

  • <?
    //PHP code
    ?>

  • //PHP code
    ?>

  • //PHP code
    ?php>