this is a short tutorial that will show you how you can create web pages using PHP and html for dynamic pages [1414], Last Updated: Sat May 18, 2024
wallpaperama
Tue May 08, 2007
26 Comments
17016 Visits
hi, i am writing this tutorial for people who are new to PHP and want to create websites with PHP and HTML.
What do you need?
- you need to know what LAMP stands for.. LAMP is, Linux Apache Mysql PHP but since linux is a complicated system thats beyon this tutorial, i am going to show you on Microsoft Windows. so instead of LAMP we will use XAMPP
X = WINDOWS- is the operating system A = Apache - is the web server M = Mysql - is the database server P = PHP - is the scripting language. PHP is a Server Side Scripting language P = PEARL - Pearl is another server side scripting language
ok, so now that you know what LAMP and XAMPP are, how do you get it.
option 1 - install it on your PC option 2 - buy it from a web hosting provider (we recommend www.webune.com)
since we are just learning all this, lets get it for free with option 1.
go to apachefriends.org and install XAMPP on your windows PC
after you have installed apachefriends, go to this htdocs folder under C:\xampp\htdocs and create a new folder called wallpaperama
we are going to save all our files in the wallpaperama folder for this tutorial
if you are using a windows computer like windows XP or windows 7, open a blank notepad.
lets create a simple hello world file, in a blank notepad, enter this code:
<?php echo 'hello world'; ?>
now save it as index.php in the wallpaperama folder
now open your browser and go to this url: http://localhost/wallpaperama/index.php
YOU SHOULD SEE THE OUTPUT: hello world
now you can use this code also for the same output: <?php echo "hello world"; ?>
notice that i use the single quotes and the double quotes, what is the difference? lets say i want this to be the output: Wallpaperama's wallpaper or "Wallpaperama wallpaper"
this is how i would parse it:
<?php echo '"Wallpaperama wallpaper"'; ?>
<?php echo "Wallpaperama's wallpaper"; ?>
do you see the difference, i would get errors if i did like this: <?php echo 'Wallpaperama's wallpaper'; ?>
if you only want to use single quotes, you will have to escape the inner single quote like this:
<?php echo 'Wallpaperama\'s wallpaper'; ?>
you can also use the print() function instead of echo. i just like the echo because is easier for me. but if you want to use the print() function you can use it like this: <?php print('Wallpaperama wallpaper'); ?>
you can combine HTML and PHP together to create webpages, for example, lets say i want to show the date using HTML and PHP:
<h1>Today's Date is: <?php echo date('M,D,Y'); ?></h1>
now that you can start getting creative, here is an example of a complete page: just copy and paste this code into index.php
now copy and past the following code into an empty notepad document:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Simple php tutorial by wallpaperama</title> </head> <body> <?php if(isset($_REQUEST['Submit'])) { echo "<h2>Hello ".$_REQUEST['name']."!</h2><hr>Don't forget to tell your friends about Wallpaperama.com!"; } else { ?> <form name="form1" method="post" action=""> Hi, what is your name <input type="text" name="name"> <input type="submit" name="Submit" value="Submit"> </form> <?php } ?> </body> </html>
now save this file as index.php then open it with your browser and watch it in action.
so if you wanted to create a php website huh!, well creating php websites are simple if you have the right tools.
there are some great tools you can get to make php websites. such as zend studio or dreamweaver, but those programs are expensive. if you can't afford these software applications your best bet is to programm your pages with a simple text editor like notepad. however, creating php files with notepad will require you to know more about html and php and will have to write more.
once you are ready to create a public website, first, step is to make sure you have php on your website. if you don't have php, you can go to Webune.com and sign up for php hosting. they have very good service.
UPDATE: some of you have replied that this doesnt work. i have followed these steps and recorded a video that this code does work:
UPDATE: also, did you know you can use short tags. if you try this code in your server and it doesnt work, its because the configuration in PHP is not setup for short tags. but if you want to use short tags, you can use something like this:
<?="this is an example of using short tags";?>
you should always use <?php tags because if you chose to move your scripts to another server, they will always work.