Basic PHP Syntax in this post I’m going to share How  Learn Basic PHP Syntax  so you will be write your own first PHP script , before you write your first PHP script you have to know the PHP script can be placed anywhere in the document and PHP script starts with

<?php and end with  ?>

and default file extension for PHP files is “.php”. for example if you are create first page in PHP and you give your page name index then this index extension will “index.php”

Learn PHP Programming Step by Step Guide for Beginners

The Basic PHP Syntax are as follows

Comments in PHP

A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is looking at the code.

Comments can be used to:

Single-line comments − They are generally used for short explanations or notes relevant to the local code. Here are the examples of single line comments.

<?php
   # This is a comment, and
   # This is the second line of the comment
   
   // This is a comment too. Each style comments only
   
?>

Multi-lines comments − They are generally used to offer pseudocode algorithms and more detailed explanations when necessary. The multiline style of commenting is the same as in C. Here are the example of multi lines comments.

<?php
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
?>

Let others understand what you are doing remind yourself of what you did – Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code

PHP Case Sensitivity

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

In the example below, all echo statements below are equal.

<!DOCTYPE html>
<html>
<body>

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

</body>
</html>

This will produce the following result

Hello World!

Hello World!

Hello World!

 

But all  variable names are case-sensitive in PHP.

In the example below, only the first variable will display the value of the $color variable this is because $color, $COLOR, and $coLOR are treated as three different variables

<!DOCTYPE html>
<html>
<body>

<?php
$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR . "<br>";
echo "My boat is " . $coLOR . "<br>";
?> 

</body>
</html>

This will produce the following result

My car is red
My house is 
My boat is

feel free to share it with your friends on Facebook ,twitter,Google+