PHP Fundamentals

0
1478

Till now we have dealt many server side programming languages. Also we have dealt with javascript which is a client side programming language along with DTD schema with XML, JSON etc. Today we will deal with a solid server side language called PHP which is used in many of the popular websites such as twitter, facebook, etc. PHP goes well with MYSQL.

So let’s learn basics of PHP in this PHP Fundamentals tutorial.

  • What is PHP?
    • PHP stands for PHP Hypertext Preprocessor.
    • PHP was created by Rasmus Lerdorf in 1995.
    • PHP is a server side scripting language i.e. everything is done on server, may it be decision making, condition checking, etc.
    • PHP can be directly embedded into HTML using
      tags.
    • PHP is free and open source scripting language.
    • PHP is a loosely typed language. It means that there is no need to define the type of a variable.
    • PHP works great with databases like MSQL. It also works nicely with other database systems.
  • What is PHP used for?
    • PHP is mostly used with databases like MYSQL. It creates a user friendly interface when dealing with data.
    • PHP generates web content/HTML.
    • You can use command line scripting with PHP.
    • PHP can even be used to build desktop applications.
    • It can be used in an object oriented or procedural manner.
    • Its more secure, more usable and a better programming language.
  • Embedding PHP into HTML
    • It is extremely easy to add PHP programming into HTML.
    • All we need to do is embed tag wherever we want to write the php code in the HTML document.
    • Let’s have a look at an example below:
    • In the above code we can see that we have a heading and 2 paragraphs in HTML.
    • A php code is embedded into the second paragraph using
      tag.
    • In the statement written above, $name is a variable name and echo is a command given for displaying/printing exactly like
      in javascript.
  • Programming Basics
    • All the programming basics are available in PHP such as variables, loops, arrays, functions and objects.
    • Variables start with $ sign. ( Eg: $myVar=’my variable’;)
    • Arrays can also have associative arrays. It is sometimes called as hash eg: array(“name” => “Brad”), here, name is a key and Brad is its value.
    • In PHP we have for, while, do while and foreach loops.
  • Object Oriented Programming
    • PHP works greatly with object oriented programming.
    • We can create classes in PHP which represent an object.
    • Objects in turn can have properties and methods.
    • Let’s have a look on a small PHP class
    • In the above code we have created a class dog.
    • $breed and $color are the private members or variables of the class dog.
    • Next we have defined an function named bark() that prints Bark when called to execute.
    • To execute the class methods, an object named $spot of type dog is created/instantiated .
    • Using the $spot object the bark() method of dog class is called using the following statement:

Thus we have gone through some introduction of PHP basics in this PHP Fundamentals tutorial.

LEAVE A REPLY

Please enter your comment!
Please enter your name here