PHP Example HTML Javascript jQuery Ajax CSS Java MORE

PHP Basics

Before going to start project with PHP you should have a basic knowledge about

  1. PHP
  2. HTML
  3. CSS
  4. JavaScript

Without knowing the basic knowledge you may face problem during Project work.

PHP syntax

A PHP script starts with <?php and ends with ?>.

<?php
// write your PHP code here
?>

The file extension for PHP files is ".php".

A PHP file contains PHP scripting code, HTML tags, css and JavaScript.

Below, we have an example of a simple PHP file.

Example

<!DOCTYPE html>
<html>
<body>
<h1>My first PHP Script</h1>
<?php
echo "Hello World!";
? >
</body>
</html>

Run It Yourself »

Note:

PHP statements end with a semicolon (;).

Comments in PHP

There are various way of commenting PHP

Example

<!DOCTYPE html>
<html>
<body>
<?php
// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment
*/
? >
</body>
</html>

Run It Yourself »

PHP Case Sensitivity

In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive.

Example

<!DOCTYPE html>
<html>
<body>
<?php
ECHO "Hello World! <br>";
eCHO "Hello World! <br>";
echo "Hello World! <br>";
EcHo "Hello World! <br>";
? >
</body>
</html>

Run It Yourself »

But in PHP all variable names are case-sensitive.

Example

<!DOCTYPE html>
<html>
<body>
<?php
$colour = "green";
echo "My house colour is " . $colour . "<br>";
echo "My pen colour is " . $COLOUR . "<br>";
echo "My shirt colour is" . $coLOUR . "<br>";
? >
</body>
</html>

Run It Yourself »

Output

php case