Saturday 11 January 2014

PHP crash course -1

                 PHP stands for HYPERTEXT PREPROCESSOR  




Short Introduction to PHP

  • php IS A SERVER scripting language like ASP
  • php script are executed on server
  • It support many databases like MYSQL, Informix, Oracle, Sybase, Solid, ODBC etc..
  • php is an open source software  

Related post : Basic funda of Internet Surfing for Person wan't to be hacker

Why PHP

  • PHP runs on different platform (windows,Linux,UNIX,etc)
  • compatible with almost all servers used in Nowdays
  • FREE available
  • easy to learn 
Before we start I wan't to clarify that we assume you are familiar with at least one any other language . Best for those who are familiar with C programming as PHP is very similar to C . only few differences are there like PHP did't require pre declaration of variable .

Preparing Environment to Run PHP program in your PC.
for Windows user Download XAMPP
& follow this Video for setup : Watch this video In HD



Start with Very First PRogram "HELLO WORLD"
A variable in PHP starts with a $ sign  
echo is funtion to print just like printf in C

 <?php  
 //simple question  
 $text="Hello World";  // test is a variable
 echo "http://beginer2cs.blogspot.com: ".$text;  
 ?>  

Related Post Easiest Way to Create Ad hoc Network (without any Software)

I suggest you to type it in your notepad save & Run for better perception .

How to find length of string similar to C . PHP also have a function name strlen() .
Now See this example program .

 <?php  
 // length of string  
 $text="hello World";  
 echo "length of string is ".strlen($text)." & string is ".$text;  
 ?>  

Here $text is a variable assign to string "hello World" . then we pass this variable to function strlen() which return length of string.

Now strpos() : fun used to search for character or world  within a string it takes two arguments first is string in which search has to perform And second is what we have to search.

 <?php  
 // strpos() : fun used to search for character or world within a string  
 $text = "welcome to World of PHP";  
 $find="of";  
 echo " String is : ".$text."\n Search position of {\"of \"}is =".strpos($text,$find);  
 ?>  

output returns the position of first occurrence of  searched element . If not found then return FALSE

PHP OPERATOR 

It is same as C programming or any other programming language .

  • +   
  • -
  • *
  • /
  • %
  • ++
  • --
  • Basic Example of using Operator


 <?php  
 // Operators in PHP +,-,*,/,%,++,--  
 $x=1;  
 $y=2;  
 $z=$x+$y;  
 echo "x=$x & y=$y ";  
 echo "z=x+y : z=$z : addition";  
 //similarly try other operator  
 ?>  

similarly try other operator

Assignment Operator

It is also same as Used in C programming Language Or any other language

 
          OPERATOR
        Example
           Is THE same As
                  =
                    X=Y
                X=Y
                  +=
                    X+=Y
                X=X+Y
                  -=
                   X-=Y
               X=X-Y
                   *=
                    X*=Y
               X=X*Y
                  /=
                  X/=Y
              X=X/Y
                   .=
                  X.=Y
             X=X.Y
                  %=
                  X%=Y
              X=X%Y



  <?php
  //Assignment Operator
 $x=1; //equality operator 
 $y=5;
 $x+=$y;  // x=x+y
 echo "x = $x";
 // <br /> for  line break
 echo "<br /> You can similarly tast other Operators ";
 ?>

Comparison Operators :

Also similar to other language like C

          OPERATOR
        DESCRIPTION
           eXAMPLE
                  ==
Is equal  to
5==8  return false
                  !=
Is Not Equal to
5!=8  return True
                <>
Is Not Equal to
5<>8  returns false
                 >
Is greater than
5>8 returns FALSE
                 <
Is less than
5<8 returns TRUE
                >=
Is greater than or equal to
5>=8 return false
               <=
Is less than or equal to
5<=8 returns false

Related Post : How to host your website for FREE (google drive )

LOGICAL OPERATOR 

         operator
         description
            Example
              &&
          And
X=6,    y=3
(x<10 && y>1) return True
               ||
           Or
X=6 , y=3
(x==5||y==5) return True
                !
            Not
X=6, y=3
!(x==y) return True

we will show you example of this in next section .....
In next section we will talk about logic in php & looping in php

PHP crash course -2 
PHP crash course -3 

PHP crash course -4 ( GET POST & REQUEST function )

Related Post : How to free your Browser from unwanted search extensions

1 comment:

  1. Hey Nice Blog!! Thanks For Sharing!!!Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging!
    best java training in coimbatore
    php training in coimbatore
    best php training institutes in coimbatore

    ReplyDelete

THANKS FOR UR GREAT COMMENT

Blogger Widgets