Basic PHP Syntax
This Article will teach you of very basic syntax of PHP and how to start environment of PHP and show output.
A PHP scripting always starts with . This is the standard code to start php environment. A PHP scripting block can be placed anywhere in the document. On servers can start php environment with <? and end with ?>.
However, for maximum compatibility, we recommend that you use the standard form rather than the shorthand form.
How to start environment of php
1. standard syntax of php
<?php echo "This is Standard syntax of PHP Script !"; ?>
2. Short tag syntax of php
<? echo "This is Short Tag syntax of PHP Script !"; ?>
3. ASP-style syntax of php
<% echo "This is ASP Style syntax of PHP Script !"; %>
4. HTML script syntax of php
<script language="PHP"> echo "This is HTML Script Style syntax of PHP Script !"; </script>
To use all tags, you will need to set or enable the configuration option in your php.ini file.
A PHP file must have a .php extension.
A PHP file normally contains HTML tags, and some PHP scripting code.
The PHP script is executed on the server, and the plain HTML result is sent to the browser.
Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of
instructions from another.
There are two basic statements to output text with PHP, one is echo and second is print.
In the example above we have used the echo statement to print the text “This is the syntax of PHP Script”.
Commenting in PHP Code
A comment is the part of a program that exists only for the human reader which can understand about code reading comment if given.
There are two commenting formats in PHP script:
They are generally used for short explanations or notes relevant to the local code.
Here we are giving examples of single line comments.
<?php # This is a single line comment # This is the second line of the comment // This is comment style echo "This is a single line comment !PHPKIDA"; ?>
They are generally used to provide pseudo-code algorithms and need more detailed explanations when necessary.
Here we are giving examples of multiple lines comment:
<?php /* This is a comment with multiline Writter: PHPKIDA TEAM Subject: Multiline comment in PHP message: This is a multiline comment script in php, you can this kind of style as well as code to writr multiline comment. */ echo "This is a multi line comments"; ?>