WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP 5 Syntax


A PHP script is executed on the server, and It work server side.


Basic PHP Syntax

A PHP script Can place anywhere in HTML .

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

<?php
// PHP code goes here
?>

The PHP file extension is ".php".

A PHP file contains HTML tags and some PHP scripting code.

Below, we have an example of a simple PHP file, with a PHP script that uses a built-in PHP function "echo" to output the text "Hello PHP!" on a web page:

Example

<!DOCTYPE html>
<html>
<body>

<h1>This is First PHP Program</h1>

<?php
echo "Hello PHP!";
?>


</body>
</html>

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


Comments in PHP

A comment in PHP code is a line that is not read/executed as part of the program. Its only for developer reader and stripped out before displaying the programs result.

Comments can be used to:

  • It tall programmer what are doing in programme
  • single line comment : generally used for short explanations or notes relevant to the local code.

PHP supports several ways of commenting:

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 block
that spans over multiple
lines
*/

// You can also use comments to leave out parts of a code line
$x = 6 /* + 12 */ + 2;
echo $x;
?>


</body>
</html>

PHP Case Sensitivity

PHP is a case sensitive language :

Example

<!DOCTYPE html>
<html>
<body>

<?php
ECHO "Hello PHP!<br>";
echo "Hello PHP!<br>";
EcHo "Hello PHP!<br>";
?>


</body>
</html>