Home Tutorial Php Phpbeginners PHP Code Syntax

 
 

PHP Code Syntax
Posted on: February 3, 2011 at 12:00 AM
Advertisement
This section contains the information about the PHP syntax.

PHP Code Syntax

PHP syntax is the set of rules which need to be followed to to write properly structured PHP code.

Given below Some rules of PHP syntax

  • The PHP script Block always start with <?php and ends with ?>.
  • You can use html, text, SQL queries with in a PHP file.
  • You can place PHP script anywhere in the html page. Given below the sample code :
<html>
<body>

<?php
echo "Hello World";
?>

</body>
</html> 

OR, This will also display the same output as above :

<?php
echo "Hello World";
?>
  • As you can see in the above code, each PHP statement ends with semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.
  • The above code must be save in a .php extension file. If it will save in a .html file, it will not execute properly.
  • 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".
  •  PHP ignore blank spaces just like HTML. For example, see the below code :
<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php
echo "Hello World!";        



	echo "Hello World!";


?>
</body>
</html>
  • In PHP, we use // to make a single-line comment or /* and */ to make a large comment block. See the below code :
<html>
<body>

<?php
//This is a comment

/*
This is
a comment
block
*/
?>

</body>
</html> 
Advertisement

Related Tags for PHP Code Syntax:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 3, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com