PDA

View Full Version : Evolutions PHP Basics Tutorial[PHP][Coding]



Evolution
10-22-2006, 12:30 PM
Evolution's PHP Basics Tutorial V2.0
This tutorial will teach you the basics of PHP


Navigation

1. Getting Started (http://www.stickpageportal.com/forums/showpost.php?p=647784&postcount=2)
2. Say Something Simple (http://www.stickpageportal.com/forums/showpost.php?p=647785&postcount=3)
3. Numbers (http://www.stickpageportal.com/forums/showpost.php?p=647787&postcount=4)
4. Variables (http://www.stickpageportal.com/forums/showpost.php?p=647790&postcount=5)
5. Arrays (http://www.stickpageportal.com/forums/showpost.php?p=647792&postcount=7)
6. Looping (http://www.stickpageportal.com/forums/showpost.php?p=647825&postcount=8)
7. Closing Statment (http://www.stickpageportal.com/forums/showpost.php?p=647870&postcount=9)

Evolution
10-22-2006, 12:30 PM
So What Is PHP?
PHP is a language used for websites whitch allows you to make your website more interactive and user friendly.
Starting A Script
For the web browser to understand your using PHP and not html or another language you must start your script with

<?php and end it with

?>

Evolution
10-22-2006, 12:31 PM
3. Saying Something Simple
Now for your first code. We are now about to make PHP say something, lets make it say hello stickpage. Here is what the code when its finished will look like

<?php
echo ('Hello stickpage')
?> Now to break it down.
we need to tell the browser where using PHP so we open and close it with

<?php
?> nest we need to tell it to put something on the screen, we do this by adding a line and starting it with

echo then we need to tell it that we are saying something we do this by adding
('') next we need to tell it what we are saying witch in this case is hello stickpage, we do this by adding our text inside the two '' so now or line of code looks like this

echo ('Hello world')now we add this inside our PHP tags so it should look like this

<?php
echo ('Hello world')
?>
now if we look at what the code would look like in a browser it should look like this


Hello world

Evolution
10-22-2006, 12:31 PM
[U]NumbersSo lets say you want to make a webpage and init you want to have how old you are in seconds and youont have a calculator. OH NOES. in this sction you will be able to make a simple sum with PHP.

we will tell the browser that we are using PHP we do this by using the PHP tags

<?php
?>
now we want to tell it that we are saying something so we add a line and add an echo

echo ('')
but when we want to make a sum we dont use the ' signs in the echo so it should look like

echo ()
now to put the sum in for this example we'll add 1 to 1, so we simply putt in our sum with sppaes at every step, our code should now look like this

<?php
echo (5 + 1)
?>
this should out put the number 10 to the browser


10

you can also add brackets to the sum if you want, here is a list of basic symbols and what they will do


+ to add
* to times
- to take away
/ to divide

now we know how to use numbers in PHP we can make a sum to find out how old you are in seconds, here is an example of a person aged 14

<?php
echo (14 * (60 * 60 * 24 * 365))
?>
that should out out put to the browser how old a person aged 14 is in seconds

Evolution
10-22-2006, 12:32 PM
Variables
Variables are words that if used in the correct way will say something else so lets say if you where going to use the word yesterday repeatedly you could just type $yes instead of using the word yesterday.

So we'll start out by using the php tags

<?php

?>
Now we must tell it what word we want to use insted of yesterday we do this by starting a line with the word we want to use instead of yesterday. NOTE: this word must start with the dollar sign!

<?php
$yes
?>
then we add an = sign to the line after a space, then the word witch we no longer wish use.

$yes = yesterday
now in this script im using there is going to be multiple lines witch means that on every line of code apart from the tags we must add a ; sighn lon the end

$yes = yesterday;
now we want to use this in an echo so we'll put in a simple echo

echo ('i went to the park $yes')
but when we use variables in an echo we must use " instead of ' and we'll need to add the ; sign

echo ("i went to the park $yes");
now our code will look like this

<?php
$yes = yesterday;
echo ("i went to the park $yes");
?>
this will look like this in a browser


i went to the park yesterday

this is pretty pointless if your only going to use the word once so we'll add more lines.
If we want to put another line under the current one we must put the code <br/> at the end of the echo. Our echo line will now look like this

echo ("i went to the park $yes <br/>");
varubles work untill you close them off so you can use them as many times as you want, ill add more lines and make a convosation using varubles.

I went to the park yesterday.
Yesterday?
Yes yesterday.

heres the php code

<?php
$yes = yesterday;
echo ("I went to the park $yes");
echo ("$yes ?");
echo ("Yes $yes");
?>

Evolution
10-22-2006, 12:32 PM
Fuctions
Functions are little pieces of codes that you add to an echo to make them do something.

So to get started ill make a simple php cde with an echo

<?php
echo ('hello world');
?>
this will look like so


hello world

now ill add a basic fucntion, function wolk like so

<?php
echo (strtouppper('hello world'));
?>
to add a function you place brackets aroud the the ('lol example') part and then put the function name after the first bracket. In the above code i used the strtoupper function witch will make every letter in the echo turn to a capital letter, and so now the output looks like so


HELLO WORLD

Here is a lidt of some functions and what they do.

Make echo into capital letters

strtoupper

Make echo lowercase

strtolower

Make echo reverse

strrev

Make every first letter of every word in the echo uppercase

ucwords

Make first letter of echo uppercase

ucfirst

Get the echos lenth

strlen

For a list of all of the functions go to www.php.net/strings
BIENG UPDATED SOON
please can you tell me if theres any mistakes.

Evolution
10-22-2006, 12:33 PM
Arrays
Arryays are a bit like variables except they are easyer To change and are much more powerfull. Arrays are like variables but wwith multiple choices of words in them.

So lets start a php document


<?php

?>

Now we add a simple variable code


<?php
$phrase = text;
?>

now we add the aray code witch is array() to the function so it look like so


<?php
$phrase = array ();
?>

Now to add the parts of the array we put them in ' and put a commer after them so ill put in some words


<?php
$phrase = array ('text', 'hello', 'world');
?>

Now to echo them out, we use the echo function and then the name of the array and then the number of the word in square brackets, note that the numbers go up in one and start at the number 0


<?php
$phrase = array ('text', 'hello', 'world');
echo ("$phrase[0]");
?>

This will echo out the word text to the browser

text
We could also change the number inside the array in the echo to change the outcome to 1 or 2 because i have put 3 choices for the array

<?php
$phrase = array ('text', 'hello', 'world');
echo ("$phrase[2]");
?>

world

tut will be updated later

Evolution
10-22-2006, 12:55 PM
Looping

Here's a situation for you, you want to place the song ten green bottles on your web page but cant be bothered to type all them lines out. But dont worry PHP will save you.

So first lets make our PHP tags


<?php
?>

Now we'll add a variable for the numbers we are going to use this will start at ten because ten is the first number we are going to use. We'll need to make two number variables because there's two different numbers in one verse.



<?php
$number = 10;
$number2 = 9;
?>


Now lets make the text we want to loop, using the echo script. We must use the variable we set for the numbers.



<?php
$number = 10;
echo ("$number green bottles standing on a wall <br/>
$number green bottles standing on a wall <br/>
and if one green bottle where to accidentally fall <br/>
there would be $number2 of bottles standing on a a wall <br/> <br/>");
?>


Now we need to add a code to make it loop. This is like so.



while(While the code is in here is true the code will loop) {
The thing you want looped
}


So we want to make it loop as long as the variable for the first number (we've called it $number) is greater than 0. so we'll put that in and also put our echo code in. To use the greater than code we use the => code.



<?php
$number = 10;
while($number => 0) {
echo ("$number green bottles standing on a wall <br/>
$number green bottles standing on a wall <br/>
and if one green bottle where to accidentally fall <br/>
there would be $number2 of bottles standing on a a wall <br/> <br/>");}
?>


But that's useless, it will loop forever and keep the numbers 10 and 9, so we put in a piece of code to make each number go down one. We'll also put it at the end of the echo so each number will go down after it has been used. The code looks like so



the variable you want--;


So we'll add two lines of code, one for each variable.



$number--;
$number2--;


Now to add it to our code.



<?php
$number = 10;
while($number => 0) {
echo ("$number green bottles standing on a wall <br/>
$number green bottles standing on a wall <br/>
and if one green bottle where to accidentally fall <br/>
there would be $number2 of bottles standing on a a wall <br/> <br/>");
$number--;
$number2--;}
?>

Evolution
10-22-2006, 01:21 PM
Thank you for reading, I hoped this helped you. If you have masterd all the things in this tut you are officialy a medium to high begginer at PHP. Thank you - Evolution

This tutorial is copyright Evolution and is to only to be shown at stickpageportal.com

Evolution
09-08-2007, 11:20 AM
Encryption
_________

Encyription is used so hackers cant get passwords or anything like that.
Encrytion will turn a word into a long list of letters and numbers e.g god encrypted in md5 is a4757d7419ff3b48e92e90596f0e7548, sound pretty hacker proof, eh?

so lets get started

first open up your php tags


<?php

?>

now to encrypt something in php you do this


type of encyption('word/words to be encrypted')


to encrypt god in md5 and save it in the variable password we should do this


<?php
$password = md5('god');
?>

and then to see what this as done we will echo it out


<?php
$password = md5('god');
echo "$password";
?>

and this will look like this in a browser

a4757d7419ff3b48e92e90596f0e7548

Types of encryption


md5
sha1
crc32


But if you only use one type of encyription on a word, it is still possible for hackers to crack it, so heres a neat little trick to keep the unwanted eyes away


$password = crc32(md5(md5(sha1(md5('god')))));

encrypt the encription multiple times, its still possible to crack but would take years

Steyene
09-10-2007, 04:38 AM
Very, Very nice Evolution, nice and simple but gets the basics through. More please.

Wtf
09-10-2007, 05:41 AM
It's big, but it's perfect. Good job.

Evolution
09-26-2007, 12:50 PM
Post get

K like, your probable wondering, I can do all these things, but why would I want to, and then i would reply with "Because PHP can do user interactions" And then you would be all like, youve not told me how to do this. So here it is.

Like, learn html forms and stuff, this is a php tutorial, not a html one. So um, lets get up a form for all ya.


<form action="color.php" method="get">
<SELECT NAME="color">
<OPTION>Red</OPTION>
<OPTION>White</OPTION>
<OPTION>Blue</OPTION>
<OPTION>Green</OPTION>
</SELECT>
</form>

Now we must note some things down here.



action="color.php"
This will be the page that the php to get the information will be on



method="get"
The method where using to send the data


NAME="color"
The name of one set of data

So now for the php

You get the data by doing the following on the page "color.php"


<?php
$fav = $_GET["color"];
?>

Now break it down now



<?php
?>

To specify that the code is php



$fav =

To save the data collected in the variable "fav"


$_GET[""]


This is the method to get the data, the method goes here if you used the get method you must put $_GET[""] and if you used the post method you would use $_POST[""]


$_GET["color"]
and we slot the name of the data in the middle of the "" whitch we got in the NAME="color" of the form



And like now if you clicked blue on the form the variable "fav" would contain blue and if you clicked white it would be white. Now to do something with this code



<?php
$fav = $_GET["color"];
echo "your favorite color is $fav"
?>

And that would say what your favorite color is depending on what you clicked on in the form.