Navigation
Poll
Would you be an active poster if Ron's Guide had a message board?


Total Votes: 67
Comments: 20 — View
Past pollsPoll idea?
Rate Ron's Guide
Rate our resource at Bigwebmaster.com
Introduction to PHP
PHP is a widely-used scripting language on the internet. This tutorial will give you an introduction to it.

PHP, which is a recursive acronym for PHP: Hypertext Preprocessor, is a very popular, open source scripting language that is particularly suited for Web development and can be embedded into HTML.

Hello World!

What kind of introductory tutorial would this be without a good ol' "Hello World!" example? Tongue Let's take a look at a very simple example of how php is used:

<html>
  <head>
    <title>PHP Example</title>
  </head>

  <body>
<?php
    
// See these? These are comments :)
    // write "Hello World!" to the page
    
echo 'Hello World!';
?>
  </body>
</html>

All of the color coded text above is PHP. Notice how it's embedded into the HTML? That's one of the great things about it. Unlike in other languages such as Perl or C where you write a program with commands to output HTML, PHP allows you to write HTML normally then just embed your PHP script directly into it.

PHP has opening and closing tags (the blue parts of the code in the example above) that enable you to jump back and forth between HTML and PHP. This is sort of like the <script> tag with JavaScript exept that the server handles the PHP code not the client's browser.

What can PHP do?

The better question would be “What can't PHP do?” PHP can do anything from collecting data from forms to creating dynamic page content to sending and receiving cookies and much more. For more information on what it can do, visit php.net

What do I need to use PHP?

In order to use PHP, your webhost will need to give you access to PHP. If you aren't sure if your host allows PHP or not, try saving the code in the example above to a notepad as *.php, then upload it to your webhost and run the file. If you can still see the PHP code after the page has loaded, your host doesn't allow PHP.

An alternative would be to install PHP on your computer, this will allow you to test PHP scripts without having to keep uploading to your webhost over and over again. If you are really interested in learning PHP, I recommend you do this.

Installing PHP isn't a horribly difficult thing to do, You can look around php.net for documentation on how to install it, but I suggest this tutorial from aesthetic-theory: Installing Apache, PHP4, MySQL4, PHPMyAdmin on a Windows System. It's very easy to follow, it should get you up and running PHP in no time at all. Smile

Hopefully this tutorial gave you a better idea of what PHP is. For more information visit php.net's introduction

Discuss Tutorial: Introduction to PHP 28 Comments
Comment by Ron on Apr 15, 2004, 1:46 am
Please post questions and comments about this tutorial below. Smile
Comment by Blade on Apr 15, 2004, 1:47 am
I thought you used print() to write stuff, I have seen several different ways and I'm getting confused....
Comment by Ron on Apr 15, 2004, 2:00 am
print() and echo() do the same thing, it's just a matter of personal preference.. you can use whichever one you're most comfortable with Smile
Comment by Blade on Apr 21, 2004, 11:08 pm
Thanx for the help Ron, as you can see I'm a n00b Grin
Comment by Ron on Apr 22, 2004, 2:46 am
No problem, gotta start somewhere, right? Smile
Comment by Peter on Apr 22, 2004, 5:00 pm
Think it's time for me to start learning php Tongue

I love your website Ron, it's brilliant Grin
Comment by Ron on Apr 25, 2004, 6:30 am
Hey Peter, Thanks Grin Hope you'll get some use out of these tutorials Smile
Comment by DarkJedi613 on May 20, 2004, 9:36 pm
You can also use print ""; (without parenthesis).

Also to print out a new line (to clean up the source file when its viewed through a browser):

print "
";

You can use the same technique to print out a quotation mark ("Wink the following code would print out a quote:

echo "\"";

The first quote starts the string, the slash tells PHP to print out the next character no matter what it is (and not to print out the \), the second quote is printed out and the third ends the string.
Comment by Emperior Eric on Oct 31, 2004, 12:54 am
hey your tutorial helped but when I saved the *.php it just took it as the name and tacked .txt on the end and then my webhost accepted it as a text file.
Comment by Ron on Nov 20, 2004, 6:49 am
Eric, sorry for the late reply. Try saving the document in notepad as "whatever.php" (with the double quotes).

« Previous [ 1 2 3 ] Next »
Post a comment
Sorry, you must be a registered member to post comments.

If you would like to register, you can do so here.
If you already have an account, please login.