Your First PHP Page
So far, I’ve introduced several open source applications built with PHP such as Joomla, PHP-Nuke and phpBB. I’ve also posted a brief introduction to PHP, which links to some useful tutorials and resources that will help you get PHP installed on your computer if you wish to test locally. All this information is a bit much to swallow all at once, so today, I want to get started right at the very basics and make a very simple PHP page.
There are tons of great tools available for developing code. My personal favorite is the most simple of all; Notepad! Notepad is a great tool for writing code because it doesn’t do anything for you. While this makes debugging difficult, it makes sure you learn your code better and understand what it is doing. I wouldn’t recommend Notepad for large projects, but for quick edits or simple pages, Notepad is a great tool which opens instantly and uses virtually zero resources.
Today we are going to write a simple program which displays, “Hello World!” on a website. Nothing too fancy, but it is the traditional starting point in just about every programming language I have tackled!
Open up Notepad:
<html> <head> <title >Hello World PHP Page!</title> </head> <body> <h1>Hello World PHP Page!</h1> <p> <?php echo "Hello World"; ?> </p> </body> <html>
Save the file with a .php extension. (ex: index.php or hello.php). Upload it to your web server and you are done!
Most of the above code is just basic HTML code for setting up a web-page. The PHP code begins with the “<?php” tag and ends with the “?>” tag. Everything between these tags is interpreted by PHP. “echo” is a simple PHP function which prints text to the screen. What you have therefore done with the simple code above it setup a web-page which includes PHP code to display the text, “Hello World!”. Try it out!
April 20th, 2007 at 7:52 am
[...] Formatting Text in Wordpress April 20th, 2007 by Deceth I’ve received several questions relating to yesterday’s tutorial, “Your First PHP Page” in regards to how I was able to include HTML code in my post. For example, if you want to make a word bold, you type <strong>bold</strong>. So the question is, how then did I write <strong>bold</strong> without the word becoming bold? The other questions I’ve been asked is, “How the heck did you do that indentation?!”. [...]
May 7th, 2007 at 12:01 pm
[...] Hello World in JavaScript May 7th, 2007 by Deceth Last month I introduced some basic PHP code which allowed text to be printed to the screen. If you do not have PHP enabled, you can do the same thing with JavaScript! The simple script shown below will once again display the classic “Hello World” text to the screen. Place the below script in your HTML page where you would like the text displayed. <script language=”javascript” type=”text/javascript”> document.write(’<b>Hello World</b>’); </script> Posted in General, Client-Side Scripting, JavaScript Link to this Entry Email This Entry [...]