TL;DR
PHP, short for PHP: Hypertext Preprocessor, is an easy-to-learn language for adding simple interactivity or talking to databases. You need a server configured for PHP and a plain editor like Notepad. Create rain.php, put a print command between <?php and ?> tags, upload it, and open it in your browser.
- Most web hosts have PHP enabled by default. If yours doesn't, contact your host and ask them to enable or install it.
- Any program that doesn't add extraneous formatting works, including Notepad or the code views of FrontPage and Dreamweaver.
- The <?php and ?> tags separate PHP from the surrounding HTML, and print displays the sentence about the developer in Spain.
This is an archived tutorial from the kirupa.com legacy collection. It covers software that may no longer be available, but it is kept online because the ideas still hold up.
PHP is a great language that web developers such as yourself should know. PHP, which stands for PHP: Hypertext Preprocessor, is very useful for adding simple interactivity or communicating with databases. Best of all, PHP is not very complicated to learn.
Unlike other languages, PHP does not require rigorous training and a long time of practice before you can create anything useful or publically displayable. In fact, by the end of this tutorial, you will have created a web page that displays some text from a PHP script!
What Do I Need to use PHP?
To display PHP, you will need to have a web server that is
properly configured to display PHP. Most web
hosts such as
mediatemple (which hosts this site) have PHP enabled by
default, so you should be set to go. To test if your server
is capable of running PHP scripts, try the method outlined
in the following tutorial:
http://www.kirupa.com/web/testphp.htm
If you do not have PHP installed, you should contact your web host and request them to enable or install PHP for you. If you are planning on setting up your own web server, there are a lot of great resources on the net that will explain how to do that.
To create PHP code, all you need is any program that allows you to enter code without adding extraneous formatting. You can use any program such as Notepad or even the code-views of FrontPage and Dreamweaver. For this tutorial, I will be using Notepad for simplicity reasons. Once you become familiarized with the PHP language, feel free to use any program that allows you to write PHP scripts.
So, let's get started with a very basic PHP example that you will create!
Here is how:
- Create a new document in Notepad or similar ASCII editor called rain.php (note the .php ending).
- Now that you have created the file called rain.php, enter the following code in your Notepad window:
<html> <body> <?php print("The developer in Spain codes gently in the rain."); ?> </body> </html>
- Once you have typed the above code, upload your rain.php file to your server.
- After you have uploaded the file, open that file in
your browser. If PHP is configured properly, you should
see the sentence The developer in Spain codes gently in
the rain. displayed in your browser.
For a live example, click on this link.
Congratulations! You have created a working PHP example. Now that we have crossed that milestone, let's learn why the above code worked.
Code Example
The following section explains why the code works the way it does.
<?php
print("The developer in Spain codes gently in the rain.");
?>
While PHP works with HTML, you need to find a
way to differentiate PHP code from the HTML code. You cannot
place PHP code randomly inside another HTML document. The
solution is to place all PHP tags between
<?php
and
?>
tags as shown above.
<?php
print("The developer in Spain codes gently in the rain.");
?>
You use the print command to display something in your browser. In our example, all you are doing is simply displaying the sentence to our browser.
I hope the information helped. If you have any questions or comments, please don't hesitate to post them on the kirupa.com Forums. Just post your question and I, or our friendly forum helpers, will help answer it.
The following is a list of related tutorial and help resources that you may find useful:
|
|
How to use the Forums |
|
|
New, Upcoming, and In-Progress Tutorials |
|
|
How to Help out kirupa.com |
|
|
Writing Tutorials |
| Cheers! | |
|
|
Kirupa Chinnathambi kirupaBlog |
Before you go, here are a few things you can do:
-
Keep reading
Read the next article in the series, Posting (Web), or check out some related content:
-
Ask a question
Stuck on something, or curious about a detail we skipped? Ask on the forums, and we’ll help you out.
Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence slop, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.
Your support keeps this site going! 😇

