Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 9th, 2004, 2:07 PM   #1
bulio
Hobbyist Programmer
 
bulio's Avatar
 
Join Date: Jul 2004
Location: Location
Posts: 140
Rep Power: 5 bulio is on a distinguished road
Php Tutorial 1

<?php

Hey, this tutorial is meant to give you information on setting up php, and writing your first scripts. Have fun. I plan to release more tutorials, with more advanced scripting, but it's the basics first, so make sure you read it B) I recommend HTML knowledge.

PHP: What is it and how do I set it up?

PHP stands for pre-hypertext processing language. This means that all the code is read before the web page is submitted. PHP is considered the most powerful web-language and is used to develop most modern sites. It can be used to create things as simple as a tagboard, and as advanced as a complete portalling system.

To set up PHP is simple. First you will need a host with php and mysql support, or you will need your own server, I would suggest downloading phptriad from download.com for this. It comes complete with MySQL, php, and folders needed.

I have my own server, now what do i do? (If your using a host discard this information)

Now you need to unzip it to a main directory on your computer, which is most likely your C:/ Drive. Now I want to go how you will have to save now, so explaining things later will be easier. Open up the server folder, and find the folder htdocs. This is where you will save all of your php documents, otherwise your php scripts will not work. Also, when testing your php scripts, you will have to insert this into your browser's url box: localhost/nameoffile.php
ALSO, make sure you turn your Apache server on, otherwise your scripts will not appear.

I've got some type of server or hosting that supports PHP, now what?

Now I think your ready for your first script/s. Open up notepad or another text editor, and insert the following code. The comments (/* blah */ Are not required.
php Syntax (Toggle Plain Text)
  1. <?php /*This is the starting php delimiter. It is required for all php code. Why doesn't what I'm typing effect the php? Because this is a comment :P */
  2.  
  3. echo 'This echos'; /*This is the echo command, it displays all text between the single quotes. Just as in your css, after each command must end with a semicolon; */
  4.  
  5. /*This is the ending php delimiter*/ ?>

Now, I think you know the output of this one, but before we get to that, let's see how we save our document. If your using a hosting server, simply save it as whatever.php, and make sure a drop down menu says either HTML document or PHP document. But if your using your own server, find the drop-down menu that says "text-file". Click it, and then select "All Files". Now save this as whatever.php.

Now to view it, in your browser, type the url location. ex:
or with your own server
Quote:
localhost/whatever.php
If done correctly, your browser should had This echoes on it. If not, make sure your server is on, supports php, you've added your <?php delimiters, and you've saved it as a .php file.

Great, now you've done your first PHP script! Exciting? I doubt it, that is probably one of the most used command (echo) you'll ever use, but it's completely useless to use without other things!

But first, let's explain what was in the comment tags. <?php and ?> are your PHP delimiters. Everything in these tell the browser that it is a php script, they are required. The echo command simply let's the browser know that text, or something else is being displayed. Also in the single quotes you can add HTML tags. Such as <b> if you want bold text. Also good practice for including HTML tags into your quotes is adding backslashes before your true quotes in your tags. Ex.
php Syntax (Toggle Plain Text)
  1. <?php
  2. echo '<font color=\"#000000\">Black text</font>';
  3. ?>
Putting in those backslashes keeps the browser from getting confused.

Now let's look at the last part of our Introduction, variables. I think you will find variables to be the most important factor of PHP, they save time, help with scripts, and so on so on.

First, what is a variable?
A variable is something that can be changed.

Let's say we had a website that managed a company, and the admin's name was Jake. Now Jake's name appeared all over the website as an admin in hundreds of pages, but the admin changed. It would be very tedious to change Jake's name to the new admin's, so it would be much simpler to include the admin name in a variable, and change it when needed. Let's see:
php Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $name = "SyringeX"; /*All strings (Variables) must include the $ sign in front of them, and the name could be anything you want. The name in quotes is what the variables values are, you can change this at any time. Things like numbers, do not need those quotes around them. And as always, remember your semicolor */
  4.  
  5. echo $name; /*When displaying just the variable, you do not need your single quotes. */
  6.  
  7. echo 'This site is run by' . '$name'; /*When including a variable with text, you must add . 'variablehere'; -- Otherwise the browser will actually read $name instead of the variables name you specified, in my case SyringeX. */
  8.  
  9. ?>

Now, save this, open it up, and see the magic of variables. If done correctly, where your $name variables were, there should be the name you specified within the variable. You can change this to whatever you want, and both text areas would display the new name. See how this can make life easier?

Now test with variables and so on by yourself, see what you can come up with just by knowing echo and variable commands.

Look forward to Part 2 of the php tutorials, where you will learn much more scripting knowledge.
?>

Created by Syringex

Last edited by big_k105; Nov 16th, 2007 at 10:24 AM. Reason: Changed the quote tags to php tags.
bulio is offline   Reply With Quote
Old Jul 9th, 2004, 2:10 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Nice tutorial.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Jul 12th, 2004, 11:26 PM   #3
TerraNerd
Programmer
 
TerraNerd's Avatar
 
Join Date: Jul 2004
Location: Vermont, USA
Posts: 65
Rep Power: 5 TerraNerd is on a distinguished road
Send a message via AIM to TerraNerd
yeah, ditto, read the whole thing
__________________
[See a gallery of my Graphic art Here.][Visit my website Here]
TerraNerd is offline   Reply With Quote
Old Jul 13th, 2004, 7:18 PM   #4
TerraNerd
Programmer
 
TerraNerd's Avatar
 
Join Date: Jul 2004
Location: Vermont, USA
Posts: 65
Rep Power: 5 TerraNerd is on a distinguished road
Send a message via AIM to TerraNerd
I went to download it off download.com and when i clicked it and it said "your download is in progress right now" it doesnt pop up, and i cannot download it
__________________
[See a gallery of my Graphic art Here.][Visit my website Here]
TerraNerd is offline   Reply With Quote
Old Jul 13th, 2004, 8:42 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Download what?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jul 13th, 2004, 8:43 PM   #6
TerraNerd
Programmer
 
TerraNerd's Avatar
 
Join Date: Jul 2004
Location: Vermont, USA
Posts: 65
Rep Power: 5 TerraNerd is on a distinguished road
Send a message via AIM to TerraNerd
phptriad, i found about 200 mirror downloads and finally got one, never mind
__________________
[See a gallery of my Graphic art Here.][Visit my website Here]
TerraNerd is offline   Reply With Quote
Old Nov 10th, 2004, 10:46 PM   #7
SyringeX
Newbie
 
Join Date: Nov 2004
Posts: 1
Rep Power: 0 SyringeX is on a distinguished road
I don't mean to be a pest, but I wrote all three of these php tutorials at another forum :mellow:
SyringeX is offline   Reply With Quote
Old Nov 10th, 2004, 11:26 PM   #8
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,667
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
i have pm'ed you.
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   Reply With Quote
Old Nov 10th, 2004, 11:50 PM   #9
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
credit not given where credit is due?
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Feb 3rd, 2005, 7:33 AM   #10
ypsonaje1
Newbie
 
Join Date: Feb 2005
Posts: 1
Rep Power: 0 ypsonaje1 is on a distinguished road
hey guys
I am novice to PHP.
Will you please guide me to learn PHP
Waiting for your reply.
you can reply me on ypsonaje1@yahoo.co.in
ypsonaje1 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Php Tutorial 3 bulio PHP 4 Jul 16th, 2006 5:00 AM
Assembly tutorial, part one. Mad_guy Software Design and Algorithms 21 Apr 15th, 2006 8:02 PM
Basic HTML Tutorial - Reuben Keeney ReubenK HTML / XHTML / CSS 14 Mar 26th, 2006 6:50 AM
Tutorial - Using MySQL in C# Darkhack C# 12 Jan 17th, 2006 10:28 AM
[tutorial] Simple G++ compiler tutorial coldDeath C++ 7 Nov 27th, 2005 1:33 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:46 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC