RSS Home Newsletter Advertising
Visit Twellow.com

An Intro To Building Dynamic Sites With PHP

What is PHP?

Originally known as Personal Home Page Tools, PHP is a scripting language that is embedded into HTML much like Mirosoft's ASP (Active Server Pages).

It can be used to do many different things that regular HTML is incapable of. A form and response page that would take two HTML files can now be done with one php file. Reading from and writing to a database is made simple now with PHP. Setting a cookie is an absolute cakewalk with PHP.

What is the difference between PHP and JavaScript?
Simply put, PHP is executed on your web server and the output is sent to your browser window as HTML. Conversly, JavaScript is sent with an HTML file and executed by the browser. The great advantage here is that the actual PHP script is kept hidden from the end user.

What do I need to use PHP?
Before we dive into the pool of digital candy that is PHP, let's have a look at what you need to get stared. PHP must be installed on the server where your website resides in order for the script to work. Unlike ASP (which will only work with mircosoft server software), PHP can be installed with almost all server types. If you are running your own server you can download PHP at PHP.net.

Otherwise, you will have to contact your host and find out if it is installed.

My First Script

Now that we are sure that PHP is intalled on our host server, let's get to our first script. If you're familiar with any kind of programming language, you know what's coming: the infamous 'hello world'. Copy and paste the following text into a text editor and save it as 'hello.php' :

<HTML><BODY>

<?PHP

$v = "Hello World";

echo $v;

?>

</BODY></HTML>

Upload 'hello.php' to your server and view it with your browser. If all is well, then you should see the text 'hello world' staring back at you. View the source. You should see no sign of the original PHP script. Great, now let's get a line by line explanation of what happened:

Line 1: <HTML><BODY> - OK boys and girls, we all know what these do...

Line 2: <?PHP - This line announces to the server that the following
text is PHP script and should not be treated as HTML.

Line 3: $v = "Hello World"; - Creates a variable named 'v' and
assigns the value 'Hello World' to it. BTW, all variables in PHP
have a $ in front of them. The ';' denotes the end of the PHP
statement. Know this.

Line 4: echo $v; - Tells the server to 'write' to the HTML file the
value of our variable.

Line 5: ?> - Very important, tells the server that our script is
finished, and it should resume treating the rest of the text as HTML.

Line 6: </BODY></HTML> - Refer to my comment on line 1.

That just about wraps it up for my PHP introduction. In future articles I plan to get into greater detail about specific PHP features. I'll explore all the types of variabes used, the use of control structures, and even using PHP with MySQL. Until then, you can browse http://www.php.net/manual/ for a complete listing of the PHP language. Or go to http://www.phpbuilder.com. Both are excellent resources for questions concerning PHP.

A Brief History
Before you go around bragging to your tech friends about how you're the master of PHP you should visit here . There you can get a short description of where PHP came from and other interesting facts. Now, not only can you wow your friends with your PHP skills, you can play it off like you've been with it from the beginning.

Robin Baker is a webmaster at WebproSchool.com. He also is the webmaster and owner of indirectdesign.com, a web and print design company on the forefront of design concepts.

News Tags: HTML, PHP, Server
About the author:
Robin Baker is a webmaster at WebproSchool.com. He also is the webmaster and owner of indirectdesign.com, a web and print design company on the forefront of design concepts.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
5 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
Subscribe to WebProNews


Send me relevant info