Responsive image
Responsive image

PHP

PHP is a server side scripting language which provides a powerful web development tools. PHP stands for PHP: hypertext preprocessor. It is also used as general purpose programming language. The syntax of this language is similar to C, C++, Java and Perl programming languages. PHP was developed by Rasmus Lerdorf in 1994 and appeared in the market in 1995 for unix and windows OS.  So, while starting php we should know about the basic understanding of the following:

Responsive image

  • HTML/XHTML/CSS
  • JavaScript

What is PHP?

  • PHP stands for PHP: Hypertext Preprocessor
  • PHP is a server-side scripting language, like ASP
  • PHP supports many databases (MySQL, Oracle, Sybase, Generic ODBC, etc.)
  • PHP files have a file extension of ".php", ".php3", or ".phtml"
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)

Basic PHP Syntax
·         A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document.

                   <?php
                   ………..
                   ………..
                 ?>
Example:
                   <html>
                   <body>

                       <?php
                             echo "Hello World";
                             print “Welcome All”;
                      ?>

                  </body>
                 </html>
·         Note: Each code line of PHP must end with a semicolon. There are two basic statements to produce the output text with PHP: echo and print. 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.
                   <html>
                             <body>
                                      <?php
                             //This is a comment
                             /*
                             This is the area for
                             a large comment
                             block
                             */
                             Echo ;
                             ?>
                             </body>
                   </html>

Variables in PHP
Variables are programmer’s defined area in computer memory which is used for storing values, like text strings, numbers or arrays.
All variables in PHP start with a $ sign symbol.
Syntax:
$var_name = value;
Example
$address= “Kathmandu, Nepal”;
<html>
<body>
          <?php
                   $pop = “Hello world”;
                   $op = “Hello Nepal”;
                   $a=20;
                   $b=16;
                   $c=$a.“ ”.$b;
                   Echo $c;
          ?>
</body>
</html>

Rules for naming a Variable in php

  • A variable name must start with a letter or an underscore "_"
  • A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )
  • A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString)

 The Concatenation Operator used in PHP
·         The concatenation operator (.)  is used to put two string values together.
                   <html>
                   <body>               
                             <?php
                                      $w1="Hello World";
                                      $w2="Have a nice day";
                                      echo $w1 . " " . $w2;
                             ?>
              </body>
              </html>
The output of the above code will be:
     Hello World Have a nice day



Post Your Comment Here