PHP Syntax &
Hello World Example
Syntax
PHP Script can be placed any where in the document. and it start’s with <?php and ends with ?>
<?php
//php Code goes here
?>
By Default php file Extension is .php but you can also override the extension in your web server settings to your required extension.
Hello World Example
PHP document contains html, Java-Script, Css or any other front end scripting language.
in below example we will use the php code in the body of html. echo is used to print data.
<!doctype html>
<html>
<head>
PHP Hello World Example
</head>
<body>
<?php
echo 'Hello World';
?>
</body>
</html>
Comments
Comment is very important ingredient in every programming language. PHP Provide Single line comments and also multi line comments option.
<!doctype html>
<html>
<head>
PHP Hello World Example
</head>
<body>
<?php
//This is a single line comment.
#This is another way of writing single line comment.
/*
*This is a
*Multi line
*Comment
*/
$value=10; //you can also comment like that.
$total=$value/*here you can also place the comment*/+20;
?>
</body>
</html>
PHP Rules
- PHP Syntax based on C
- PHP Every line terminates with semi colon (;)
- PHP Keywords like (e.g if-else,for, echo, etc.), classes, functions and user-defined functions are not case sensitive.
- PHP Variables are case sensitive