PHP

PHP Syntax:

A PHP script is executed on the server and the plain HTML response returned by server to the web browser.
The PHP echo and print statement is used to output data to the screen.

PHP script starts with and ends with ?> for example-





My first PHP page




echo "Welcome to the world of php script";

?>



PHP Short or short-open tags example-


echo "It is php short open tag example.";

?>

Note:- You have to on the short open tag in php.ini file.

HTML script tags:


Comments in PHP:-

A comment in PHP code is a line that is not interpreted as part of the program by PHP interpreter. Comments are added with the purpose of making the source code easier for programmer to understand, and are generally ignored by compilers and interpreters.

Why we use comment in programming?

Let others understand what you are doing:

  • Making the source code easier for any programmer to understand even who have not write the code.
  • Comments can also remind you why you wrote the specific line of code.

PHP supports different type of commenting such as single line comment and multiline comment for example-





// 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 = 5 /* + 15 */ + 5;
echo $x;
?>


PHP Case Sensitivity

Keywords in PHP such as if ,else , echo ,while etc are not case sensitive. but classes, functions, and user-defined functions are case-sensitive. The following all the three echo statements are valid in PHP.





ECHO "Welcome to the world of php script!
";
echo "Welcome to the world of php script!
";
EcHo "Welcome to the world of php script!
";
?>


In PHP all variable names are case-sensitive for example-





$msg = "PHP variables are case-sensitive.";


echo $msg ;
echo $Msg; // $Msg print nothing
?>


Back to Top