Here i will be talking about what is PHP and what you will need in hand to begin scripting in PHP.
PHP is a widely-used general-purpose scripting language that is especially well-suited for Web development and can be embedded into HTML.
PHP is an free, open-source server-side scripting language. And as you will see soon PHP code can be embedded in HTML. PHP files usually have extensions like example.php
1. What do you need to start PHP coding?
A.a PHP server (eg. Apache)
B.a database server (eg. MySQL)
C. a Text Editor (eg. Notepad++)
D. Web Browser (eg. FireFox)
I assume some background knowledge of HTML, JavaScript, VBScript or any familiarity with web pages. I suggest you to start learning web markup language (HTML) by going through the PAGE SOURCE of the web site you like.
Collectively you will need a Web-Server installed in your PC.
These two services (PHP & database server) when run in background in your personal computer you can timelessly start embedding PHP code in your HTML documents and view them.
2.Where to get webserver?
You can prefer any of the two webserver listed below to setup a PHP coding environment.
A. Wampserver http://www.wampserver.com/en/
or
B. XAMPP server for windows. http://www.apachefriends.org/en/xampp-windows.html
to take assistance in setup process please prefer the references in the respective web pages.
3. What Next?
a.Open up your Firefox or any other web browser you use.
b. Type http://localhost or the loopback ip 127.0.0.1 in the address bar and hit enter.
(if you have successfully setup XAMPP downloaded from above links you should see some page like this in picture. see some example codes there in left sidebar in the XAMPP localhost page. If this page doesn’t appear there might have been some mistakes in setup! retry!)
c. Get ready to run your own PHP code.
4. General HTML Page
<html>
<head>
<title>
<!-- this will be the title of your web page -->
</title>
</head>
<body>
<!—the content of your page goes here.-->
</body>
</html>
So you are familiar with this HTML tag systems. okay it’ll help a lot to understand PHP thing.
6. Where does PHP comes in HTML pages???
i would like you to think of the situation when you required to update the PAGE content in above HTML page fetching some information from the database file. How’d you do that? HTML has no inbuilt features to support file access. Now let’s suppose we needed to change the content of the body depending upon the user interactions on the page and using information from our files which store the unprocessed raw information. So can you locate the SPOTS in the HTML page in the above markup - where you want the content to be generated dynamically???? There you go.. we’ll add PHP where we need. Just grasp point 7 nicely.
7.Does PHP has tags like <HTML>?
There are opening and closing tags each pair for all of the HTML elements in a web page. Like <head> and corresponding closing tag </head>. But you don’t need to be concerned so much about the tags here in PHP. Just remember a tag..
<?php Opening Tag
//Your PHP code goes here
// no more tag boundaries here
// you are free to write any valid PHP code here within these tags
/*
If you are familiar with C/C++ then the PHP will be easier for you to grasp in.
*/
?> Closing Tag
8.HelloWorld.PHP
Let’s write a HelloWorld.php which will display a page with Hello World and body with message Welcome to PHP. For this we need to INSERT dynamically the title of the page and content of the body. Copy paste the following code in notepad++ or some other text editor. Save the file as helloworld.php
<html>
<head>
<title>
<!-- this will be the title of your web page ->
<?php
echo “Hello World!”;
?>
</title>
</head>
<body>
<!—the content of your page goes here.—>
<?php
echo “Welcome to PHP”;
?>
</body>
</html>
9.How to View the PHP page??
Now when the page has some PHP code in it and saved as .php extension the page becomes PHP page, just to mention.
If you have installed XAMPP:
put the helloworld.php file to the subfolder htdocs inside XAMPP root folder.
If you have installed WAMP:
put the helloworld.php file to the subfolder www inside wamp root folder.
type: http://localhost/helloworld.php in the web browser. See the output.
Be sure the webserver is running. Ensure it by typing loopback ip or just http://localhost in web browser. You must see some information there like in above picture.
the output will be:
I hope you got the all setup and Hello World! thing in PHP. So now try writing some more code. Go google for other references!
10. So what do we mean by Dynamic at all??
It’s quite simple. The PHP file which contains PHP code executes in the SERVER SIDE(Web-server). You as the user sit in the CLIENT SIDE (Browser viewer). So when PHP thing is executed in SERVER SIDE that generates some HTML code so that your browser can enjoy the content without ruining your whole page :D Got it. We used PHP code here to do something in SERVER SIDE. hmm Dynamic!
Now think it as a little bigger - replace the simple echo code above with some MySQL queries and all DATABASE accessing & processing code, display the output in the location where you want in the page. Yeah, thing are dynamic these days.
This article is intended to explain the simplicity of PHP setup and coding. Specially dedicated to those who excuse themselves saying -“i can’t learn PHP!” or “PHP is tough to start!” Thanks for reading.

0 comments:
Post a Comment