|
Basic PHP Syntax
PHP codes always begins with . A PHP code can be placed anywhere in the document. PHP tags can also be specified by only when shorthand is enabled on servers. Still it is recommended to use the standard form ()
A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code. Below, we have an example of a simple PHP script which sends the text "Hello World" to the browser:
Example-1:
<?php echo "Hello World"; ?>
|
Note:
- Each line of code in PHP must end with a semicolon. The semicolon act as a separator and it distinguish one set of instructions from another.
- There are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text "Hello World".
- The file must have a .php extension. If the file has a .html extension, the PHP code will not be executed.
Comments in PHP In PHP, we use // to make a single-line comment or /* and */ to make a large comment block.
Example-1:
//This is a comment /* This is a comment block */ ?>
|
|