PHP TUTORIAL FOR N00BS PART 1

This tutorial was written by me and has been posted on forums at wicked-site.com and Geodogs.com
I hadn't even posted it on my own then lol!
Are you thinking Why are the colours crappy? Well because I havent set them :P

If you have ever used C++ this will be easy!

Okay I will teach you the basics, bear in mind after this tutorial you will not be uber leet, far from it so don't go thinking you are


First you need a host that supports php find one.
Then you want to know if it really does have working php and the version.

Make a text file called test.php

Files ending in .php will be preprocessed as php and the code will not be seen by the viewers.

Open up the file

Before I continue I'll tell you a little bit about comments.

//This is a commnent for one line

/*
Anything between these are comments
use these for temporarily 'cutting out bad code
*/

The comments are kinda like developer notes but are more usefull for temporarily removing stuff
so if you went

CODE

<?
echo "Guess what?!";
//echo "fuck you!";
?>


The page will look something like this:

CODE
Guess what


Try it copy the
CODE

<?
echo "Guess what?!";
//echo "fuck you!";
?>

into your test.php upload it then run!

Stuff between comments will not be shown, /* starts a multi line comment */ ends one!

W00t we are getting uber leet ... oops exageration there but don't worry we will soon be super n00bs (I say we I mean, You not me )

back to the code.

You should now have test.php open delete everything if you bothered to do it.
type this in:
CODE

<?
phpinfo(); //the phpinfo function
?>



I'll go through the code so you can understand
<? tells the code to start running php anything inside is php.
phpinfo(); tells it to run the phpinfo() function when run this will gather information from your server config and output them in a table
?> tells it to stop the php

outside <? ?> tags you can put normal HTML but it is IMPORTANT that ALL PHP is inside these tags, you can also use them as much as you like.

upload and run the program, read all the info like php settings and mysql Interesting huh?

Okay now that contains a lot of information, for security reasons delete test.php now!

You have just written your first script (Second if you did the comments one)

I will now tell you about the functions
anything that ends in () is a function, certain functions let you pass parameters into these brackets like this:
killplayer(4);

that would say run the function kill player with the parameter 4.

Thats as far as I'll go on that because functions get way more complicated for your tiny developing n00b brain! When you start returning stuff..

To display text you would use
echo()
like this:
CODE
echo("fuck you!");

you can also use print
CODE
print("fuck you too buddy!");


since you are using strings note they have "'s around em.

Feeling uber leet yet? well ur not yet!
I bet you are thinking whats with all those fucking ; 's

those little bastards are the most annoying thing ever, they tell the php that the line has ended, 90% of your problems will come from forgetting to use these!
Just look where I put them and where I don't you will soon learn.

Variables!
A variable is kinda like a storage for data you can call em whatever you want so long as they begin with $

here are some variable names:
$greenbottlesstandingonthewall
$name
$power
$hp
see?
to set them you would go:

CODE
$greenbottlesstandingonthewall = 99;


you can do maths with em too:
here is a full php script:
CODE


<?
//Green bottles by MCFR4G 2003
$greenbottlesstandingonthewall = 100;
for ($i = 1; $i <= 100; $i++) //This is a for loop examine it.
// Stuff in the loop will loop until the loop is happy! $i is avariable used to count loop
{ // Use these at start of a loop, also notice how I indented the code, do this its good practice makes code easier to follow.
echo("<BR>$greenbottlesstandingonthewall Green bottles Standing on the wall, $greenbottlesstandingonthewall Green bottles standing on the wall and if one

green  bottle should accidently fall <BR>"); //   <BR> means newline you can echo HTML tags :-D
$greenbottlesstandingonthewall--; //This is decrement '--' it is the the same as $greenbottlesstandingonthewall - 1,
//there is also increment'++'
echo("They'll be $greenbottlesstandingonthewall Green bottles standing on the wall!<BR><BR>");


}  // end of loop

echo("<BR>Bravo Bravo!"); // out of the loop now
?>


Study that script and try to see what it is doing. read the comments //

What it does is sets green bottles to 100 then starts a loop for 100.
It will then repeat 100 times saying howmany green bottles they are then smashing one :-D
When it's looped 100 times it will say bravo bravo


You are now a super N00b! - Look out for part 2 Whenever I do it!

Any questions? or comments? Also if theres any mistakes tell me please :-D