Saturday, March 14, 2009

Basic PHP Syntax

  • The word PHP stands for HyPertext Preprocessor. PHP is an open source software and free to use. This is a server side scripting language which means codes written in php are executed on server side.
  • All PHP code block starts with <?php and ends with ?>. You can also use <script language="php"> </script>
  • If shorthand support is enabled on the server then you can start a PHP scripting block with <? and end with ?>. Short tag are enabled via the short_open_tag php.ini configuration file directive, or if php was configured with the --enable-short-tags option.
  • Each code line in PHP must end with a semicolon (;). Semicolon differentiates between two instructions.
  • In PHP, with echo or print command you can show output text.A php file can contain html tags just like a normal html file.
  • Note that the closing tag of a PHP block at the end of a file is optional.
  • Two types of commenting code in php script is available. For single line comment use "//". To comment a large block write code inside /* and */

Below is an example of welcome.php.

<html>
<body>
<?php
echo "Welcome to the PHP World";?>
<br> </br>
</body>
</html>
<?php
echo "Welcome from the site http://arjudba.blogspot.com";
?>

Save welcome.php inside htdocs folder (If you use apache web server) and run it from browser. The following will be output.

Welcome to the PHP World

Welcome from the site http://arjudba.blogspot.com
Related Documents
Datatypes in Php
Integer and floating point number in Php
Variables in PHP
Magic constants in php
Boolean datatype in Php

No comments:

Post a Comment