WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP 5 Syntax


The PHP script executes on the server and sends pure HTML results back to the browser.


Basic PHP Syntax

PHP scripts can be placed anywhere in the document.

PHP script starts with <?php Start with ?> End:

<?php
//PHP Code
?>

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

PHP files usually contain HTML tags and some PHP script code.

Below, we provide a simple example of a PHP file that can output the text "Hello World to the browser!":

Example

<!DOCTYPE html>
<html>
<body>

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

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


</body>
</html>

Each line of code in PHP must end with a semicolon. A semicolon is a delimiter used to distinguish instruction sets.

With PHP, there are two basic instructions for outputting text in the browser: echo and print .


Comments in PHP

PHP supports several ways of comment:

Example

<!DOCTYPE html>
<html>
<body>


<?php
//This is a single line comment PHP

/*
This is
PHP multi-line
Notes
* /
?>


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