PHP Syntax

PHP scripts are executed on the server, and the result is sent back to the browser as plain HTML.

Tutorials dojo strip



Basic PHP Syntax

PHP scripts can be embedded anywhere within an HTML document. They start with <?php and end with ?>.

PHP

By default, PHP files have the extension .php. Typically, these files contain a mixture of HTML tags and PHP code.

Example

Here’s a simple PHP file containing both HTML and PHP code:

PHP

Note: PHP statements must end with a semicolon ;.




PHP Case Sensitivity

While PHP keywords (e.g., if, else, while, echo, etc.), classes, and functions are not case-sensitive, variables are case-sensitive.

In the example below, all three echo statements are valid and equivalent:

Example

PHP

However, variable names are case-sensitive. Consider the following example where only the first statement displays the value of the $color variable correctly:

Example

PHP

In this instance, $COLOR and $coLOR are considered different variables from $color.

Tutorials dojo strip