Monday 28 November 2016

Chapter 1(PHP) What is php and how to write a simple program in php and how to execute it ?



PHP is HyperText Preprocessor language.It is a scripting language basically used for web development.With the help of php language we can make websites .
Php is basically server side scripting language which runs on a web server we can write a code in this language and than that code will be executed on web server.
php language is embedded into html .

In  simple language we can say that php is used for web development or for making websites.

How to write a simple program in php language❓❔❓

Before writing the example of php i want to tell you that first we have to know about html language before writing the code in php .but if you dont know about html dont worry see my blogs and you will learn .i will also put my blogs on html language in which you will learn html language.

To RUN a php PROGRAM we also need web server beacuse as i explain above we need a web server to execute php code so you will have to download wampserver (which is web server)and  install it.there are also other web servers like apache and many more but i use wampserver.
we can write the code of php in notepad and save it with extension .php for example 1.php

SO HERE THE SIMPLE AND BASIC EXAMPLE OF PHP PROGRAM
                                  
                                                     <html> 
                                                    <head>
                                                    </head> 
                                                     <body>
                                                    <?php 
                                           echo "THIS IS RAJAT"; 
                                                      ?>
                                                     </body> 
                                                    </html> 

  we can write the basic php program like this we have to write all the code in body tag <body>.
<?php   is starting method of php code.
Suppose we are going to wite a program in php code than we have to write <?php tag which shows that code should be written in php language and after writing the code we have to close this tag like
?>

In php we use echo .basically what is echo and why it is used ? 

echo is predefine function used to display the content the content of program which we want to display when the code is get executed  
we can write as echo "rajat";
the text we want to display can be written in "" and ends with ;

for example in c++ language we use cout to display.
 All the tags should be closed in proper order if we cant close all the tag than our program will not get executed it will show error .



NOW THE THING IS HOW TO EXECUTE THIS PROGRAM

IT is very simple to execute it first we have to download wampserver and after that we have to install it in c drive and also create a shortcut on desktop.
now we have to double click on wampserver shortcut that created on desktop than a dialog box will appear on screen which will ask you for permission that do you want this app to run you will have to excute or click on yes.
now you will see w sign near the battery icon which is of red color it will changes to green .

after that you will have to left click on that w and differnt options will display you will have to select local host from these option.
                                           
 when u click on local host it will open in browser and dispaly as
                                                   
now you will have to set path  or environment varible 
we have to go in c drive we will see a folder name wamp we have to open it
now we see many folders we have to open bin folder and copy the address of that 
after that you will have to go in start button and write environment variable or we can open it from control panel system properties
now go in advance and click on environment variable 
now click on new button given ablove and a dialog box will appear like this
now write variable name as path and copy the link of bin from c going in wamp folder and open bin 
copy that in variable value and apply it or save it.


now we have to again open c drive go in wamp folder and after that you will see many folders 
open the folder www and create a new folder with any name which you want to give to save our program code which we write in notepad 
you have to save all the programs in that folder which you created in www 
now you have to left click on the green wampserver sign which is near battery sign and open local host
you will see your folder in your projects as i see my folder rajat in your projects
now open that folder and click on the program that you will save in this and it will get executed and dispaly the output



IF you  have any query regarding this than please post a comment .


No comments:

Post a Comment