For generating a PHP file, the developer has to create a file name using .php extension. This file seems like HTML file and saves as a plain text.
For generating a PHP file, the developer has to create a file name using .php extension. This file seems like HTML file and saves as a plain text.The most common basic syntax are:
Naming Files
For generating a PHP file, the developer has to create a file name using .php extension. This file seems like HTML file and saves as a plain text.
Comments
Writing comments is a good habit because it directs about what you have done. You will feel no difficulty while making any change or modification. A well coded script is always full of balanced comments which makes the code absolutely perfect. A symbol of ‘//’ or ‘/*’ has been placed to leave the comment. The syntax of ‘//’ is marked for a single line comment and is used at the beginning of each line while ‘/*’ is used for commenting several lines and used at the top and bottom of the comment. The comments surrounded by the comment syntax are not executed while compiling the programme nor displays on the screen of the end users.
Let’s see the examples:
<?php
// This line will not execute in the compiling.
// And also not displayed on the screen
print (“Hello Buddy”);
/*
These lines will also be ignored.
Use this type of comment symbol
If you need a large comment
*/
print (“How are you?”);
?>
3.1.2 Code Syntax
Start of Code
Each block of PHP code begins with ‘<?php’ or ‘<?’ if server support it, and ends with ‘?>’. Mostly every chunk ends with a semicolon. For Example:
print ( );
Here, print is a function and the text written inside the parentheses are printed on the display screen. At the end of the parentheses, input a semicolon, which terminate the command.
The same command can be written like “print”, which also works without the use of parentheses. The command echo () is the same as print ().
For effectively execute, compile and running of the PHP code, it is essential to write it in the correct mode, for example:
<?php
print (“This is Rose India”);
?>
or
<?php print (“This is Rose India”); ?>
Both the chunks are correct and equally effective. It is advisable to use the first chunk in bigger and complex programmes.