Step By Step PHP Comprehensive Guide For the Absolute Beginner

What is PHP?

PHP stands for PHP: Hypertext Preprocessor. PHP is mostly used and it is a scripting server side scripting language. The scripts of PHP always executes on the server. You can download PHP with no cost means free available to download. Inside PHP file, you can use HTML, java script, Jquery, Ajax etc.

PHP File:

A php file contains HTML, jscript, jquery etc. PHP always executes on server means for executing php file, one server is required. A file which has extension .php or .php3 is known as php file.

Why use PHP?

Php provides many platforms to run means php runs on several platforms like windows, Mac, Ubuntu etc. PHP provides the compatibility with most of web servers such as wamp, xampp, IIS, Apache etc. PHP is free to download from its official site www.php.net.

Requirement to learn PHP:

You should have knowledge of HTML, CSS, Java script etc. then you can easily learn the PHP in easiest way.

Tools to run the PHP:

  • Web browser is required to execute the php file.
  • Your system should have a web server like Apache, xampp, wamp etc.
  • These all servers is free available, you can download form official sites.
  • An editor is needed to write the HTML.

Choose Browser: you can choose one browser such as

  • Mozilla Firefox
  • Internet Explorer
  • Google Chrome

Choose Server: you can choose one of server such as

  • XAMPP
  • WAMP
  • Apache

Choose Editor for PHP:

Editor helps you to write the PHP code in an efficient manner and provides the proper help and hints when you use some tag then editor provides you the options to choose the attributes and also values for that particular tag which you apply for the formatting. There are various editors are available in the market but most popular are Notepad++ and Dreamviewer.

There are several editors for writing the PHP such editors which are as follows:

  • Notepad++
  • Dream viewer
  • Brackets
  • Bluefish

Syntax of PHP: the php syntax tells you how php starts in file. The syntax is as follows:

php-syntax

PHP code always starts with <?php and ends with ?> this sign. A php file contains any number of php blocks to make the separate portion, some time we needed separate portion.




Where to save the PHP file: In XAMPP server, you have to save the file with .php extension in “C:\xampp\htdocs” and inside htdocs you can make your own folder then save file in folder. It is better to save programs in folder shown in below figure:save-php-file

Here we have made a folder named PHPDemo. Now save the programs in this folder.

How to run PHP file on server? : First you have to start the server and type localhost in the URL and hit enter. Now localhost will be open and now you have to give the path of your file and hit enter. This process is in the following diagram:

run-php-on-server

How to print message in PHP? : A function echo is used to print the statement in the PHP. Inside double quotes you have to give the message and this also prints the variables values even you have given variable inside the double quotes. The syntax is as follows:

print-in-php

Variables and data type in PHP: variables in php is declared with $ sign such as $a; and there is no specified data type in PHP as C or C++. In PHP, the value of variable defines the type of variable. The example is as follows:




variables-data-type-php

Inside this we have declared variable named and also initialized with value 10 means this value determines the data type of this variable means this variable is of integer type. In PHP, one variable can be declared many times. Thus you can say that PHP is loosely coupled server side scripting. The output of program shown in above diagram is as follows:

php-data-type

How to use OOPs in PHP: PHP provides the features of the object oriented programming language such as class, object, inheritance, polymorphism etc. In PHP, you can declare a class using the following syntax:

oop-php

In this syntax, class is a keyword and className is name of class. You can also use the function inside the class. The syntax is as follow to make a function inside the class:

oops-php

In this syntax, function is a keyword and you have to give the name of function and you can also give the arguments and provide the body for it. To call the function, you must create object of the class then you are able to call the function. The syntax to create object and call function using function as follows:

oop-php-1

The example of function in class as follows:

<?php

 

class A

{

           

            function display()

            {

                        $a = 10;

                        echo “the value of a is : $a”;

            }

}

$ob = new A();

$ob->display();

?>

The output of this file is as follows:

the value of a is : 10

How to use HTML is PHP? : You can use HTML in PHP. You can understand this using the following example:

<?php

 

            echo “<html>”;

            echo “<head>”;

            echo “<body>”;

            echo “<p> HTML mixed in PHP”;

            echo “</body>”;

            echo “</head>”;

            echo “</html>”;

?>

You can mix the HTML using the echo function; you have to write the tags inside echo and another ways to use HTML in PHP file is as follows:

<html>

<head>

<body>

Message using HTML

<?php

            echo “<br> Message using PHP”;

?>

</body>

</head>

</html>

PHP provides various features as follows:

1.     Object oriented programming

2.     Exception handling

3.     Special type of array called associative array

4.     Validation programming

5.     Interfaces

6.     Robust security

7.     Connectivity with MySql

8.     Connectivity with more database

9.     You can connect android apps with PHP

10.   The popular example of PHP is Facebook

India OnGo

Hello Visitors. I hope you are getting desired information on this website. I am the founder, content creator, editor, administrator of this website. i created this website in 2015 to aim to provide accurate information to the visitors. I am in this field for more than 10+ years and trying to provide information with accuracy and references. If you find any wrong information in the content, please write and email to me from contact page.

Leave a Reply

Your email address will not be published.