PHP for beginners

No, these are not photoshop tutorials!

Moderators: Community Moderators, Tutorial Writers

zeus_zf
Posts: 7
Joined: Fri Nov 02, 2007 5:14 pm

PHP for beginners

Postby zeus_zf » Tue Nov 13, 2007 5:04 pm

hey people im writeing this for all you that want to learn php




ok the first thing you should know is your os (unless certain versions of linux) will not have php enviroments installed.
so cant not be easyly created by notepad alone also even if your computer does have php enviroments enabled you will only be able to view it (it as in the compiled version) as a client
which basic means you can only see what the end product of your script will be once you view it in your browser if testing on your own server or on a host that you have if you install it on your own pc then you will have to go to http://127.0.0.1 when you have the server up and running.

step 2 how to get the php installer

look for a program called php triad it will install apache, php and mysql. which on a whole is VERY useful. they are tool which will come in handy. you can also look for other php installers but this is the one i like and thats why i recomend it but you will able to get more infomation from the sites at the bottom of my post.

step 3 hopefully you have the php enviroments installed or have a host. like http://5gigs.com

you will be able to start testing scripts

ok for the first test you will learn about varibles

varible always have a $ at the start of the sentance they can not have - in them spaces or start with a number. varibles are good for storeing data and can be changed in what ever way you can think of.
so here is the sample script
Code:

<?php
$testvar = " test me baby ";

print $testvar ;
?>


what this will do once viewed in the browser via the webserver
will print the words

test me baby.

now the = means its equal to

and you put " " with the words test me baby in because its a string

but it can also be a file or even a function.

and we always put ; at the end of a statement or function.

thats the end of the first part to the tutorial next more stuff

but as i said the sites that will help you

http://www.php.net
http://www.phpfreaks.net
or it might be
http://www.phpfreaks.com

http://www.php.net/manual/en/tutorial.php

i forgot to add one thing that i should of said. like most web scripts they have to declare them selfs like html. to declear that the script is php you have to start with <?php and end the script with ?>


thanks and the program should already be in the download section..


ok heres the next step on using varibles. i havent got a working server with me at the moment. tho i have a few tools with me.
so we have our script with a test string in it.


so say we have a html submit form that submits jus a single string so you can make you varible more flexible.
Code:
<html>
<form action="test.php" method="POST">

input data please : <input type="text" name="test" />

<input type="submit" />
</form>
</html>



now jus make this as a normal html file.
hopefully you have done html already so i wont need to explain that.


now we make the php script that will handle the input "test" and look at or change the varible. we will also use a if.. else statement.
this is incase the data input is not true it will return false.
Code:

<?php
$test = $_POST["test"];
if ($test === "admin")
print ("welcome admin");
else
print("piss off!")
?>



what i did there was the simple start to making your site passworded.
the great thing about php is clients will only be able to see whats in promted by the browser so they wont be able to see the password at all unless you did Code:

print("my password is :admin");


or something stupid like that.

you can see a version of this script ready made at http://pureone.t35.com/guess.html forgive me for the pop up that happens the host is shitty please disable java script before you goto the site. dont disable java disable java script..

ok ill explain what happen in the code..
first i stated that the incoming data from the html script would become $test. then i said that if the varible $test was identical to "admin" print welcome admin. if it wasnt identical to admin (if returned false.) print "piss off".

ok now for differnt ways to change the data input.
this one is one i made a little while back its not very useful but shows a point on how flexible varibles can be.
Code:
<html>
<form action="math.php" method="POST">
first nubmer please: <input type="text" name="no1" />
second number: <input type="text" name="no2" />
third : <input type="text" name="no3" />
4th : <input type="text" name="no4" />
<input type="submit" />
</form>
</html>



now the php form
Code:

<?php
$no1 = $_POST["no1"];
$no2 = $_POST["no2"];
$no3 = $_POST["no3"];
$no4 = $_POST["no4"];
{
if (($no1 == "") && ($no2 == "")
&& ($no3 == "") && ($no4 == ""))
print(" duh! ");
else
{
print(" the ip you submited in binary form is :") ."\n";
echo decbin($no1) ."\n";
echo decbin($no2) ."\n";
echo decbin($no3) ."\n";
echo decbin($no4) ."\n";
}
}
?>



ok what i did extra here function and statement wise is 1 the && which means and. 2 the "" which means empty and 3 changed the varible with a function decbin which changes numbers to the binary equiv.

so the way it would go is
takes the varibles makes them what there ment to be submited info.
and them check IF there is no data in the varible is there is data in the varible. print the data in binray form..

html = hyper text mark up languge

php = hypertext processer

its a languge for websites used for databases and all sorts. very secure. unless not scripted right. most forums are php because php can acces databases such as mysql. you can tell what type of languge a website is using by 1 looking at the url you are at. 2 reading the source code.

ok php has built in maths fuctions much like most languges. Code:

+ = plus
- = minus
/ = divide
* = multiple



no say your doing something in maths you want to create a certain value for something say VAT which is the tax that gets added on to your purchase in uk. now this may not be the right way to find the tax for a product but it should hopefully explain how to do maths with php.

ok so you have you submit form which will take in 1 number.
Code:

<?php
$number = $_SERVER['number'];
$number2 = ($number/100)*17;
print $number2;
?>



now this will divide the number posted by 100 then times the number2 divided by 100.

making strings more global.

lets look at search engines for a moment. how would do they make them universal? well one thing i have noticed with google is no matter what way you put the letters caps or not it will always find the same results. this is because they will reshape the words submited. how would they do that you make ask? well by using php built in functions.

stroupper() = all upper case letters.

so Code:
$test = "test this";
print stroupper($test);


will print TEST THIS

strolower() = all lower case letters.

so Code:
$test = "TEST THIS";
pring strolower($test);



will print test this

another function that can be used for correcting grammer.


ucwords = this makes the first letter of each string goto caps.

so Code:

$test = "test this";
print ucwords($test);



will print Test This.

but say some one has submited something that looks like

tHiS
if you use the ucwords on it you will get THIS because it does not touch any other letters then the letters at the start of the string. so how to correct this? well you need to chuck another arguement in there.

so Code:

$test = "tHis IS A gIANt wAstE OF tIME";
print ucwords(strolower($test));



which will print This Is A Giant Waste Of Time.

G-Brain
Posts: 82
Joined: Tue Aug 07, 2007 11:21 am
Location: The Netherlands
Contact:

Re: PHP for beginners

Postby G-Brain » Tue Nov 13, 2007 11:41 pm

Maybe you should read a couple of tutorials before writing your own...

jd2kuk
Posts: 1537
Joined: Fri Mar 16, 2007 12:19 am
Location: UK
Contact:

Re: PHP for beginners

Postby jd2kuk » Wed Nov 14, 2007 7:34 pm

Quaon wrote:I didnt bother reading it,


Ha ha :D

G-Brain
Posts: 82
Joined: Tue Aug 07, 2007 11:21 am
Location: The Netherlands
Contact:

Re: PHP for beginners

Postby G-Brain » Thu Nov 15, 2007 7:50 pm

What it actually tells you about PHP is this:
- Variables
- HTML Forms
- If statements
- Math
- String manipulation

As opposed to, for example:
- Syntax
- Variables
- Echo
- Strings
- Operators
- Comments
- Includes
- Control statements
- Forms
- Functions
- Arrays
- Loops
- POST & GET
- File handling
- Sessions
- Cookies

As any reasonably competent tutorial would do. Also, the spelling is poor.

User avatar
phiber
Site Admin
Posts: 260
Joined: Sun Oct 13, 2002 11:26 pm
Location: Cakovec, Croatia

Re: PHP for beginners

Postby phiber » Sat Nov 17, 2007 6:31 pm

Tut moderator should have seen this... tut mod wtf?

G-Brain
Posts: 82
Joined: Tue Aug 07, 2007 11:21 am
Location: The Netherlands
Contact:

Re: PHP for beginners

Postby G-Brain » Sat Nov 17, 2007 6:59 pm

phiber wrote:Tut moderator should have seen this... tut mod wtf?

Perhaps you need a replacement :mrgreen:

Fergie1
Posts: 257
Joined: Sun Jul 15, 2007 2:22 pm
Location: UK

Re: PHP for beginners

Postby Fergie1 » Sat Nov 17, 2007 7:31 pm

I did see it, but I know bog all php. And the forum permissions weren't set properly so i just left it.

Fergie1
Posts: 257
Joined: Sun Jul 15, 2007 2:22 pm
Location: UK

Re: PHP for beginners

Postby Fergie1 » Sat Nov 17, 2007 8:15 pm

G-Brain wrote:Perhaps you need a replacement :mrgreen:

Nice try, but im the one in charge of the O Mods. :wink:
But G-Brain, since you've been out of trouble for some time now, if you submitted a tut you would be considered for a writer.

G-Brain
Posts: 82
Joined: Tue Aug 07, 2007 11:21 am
Location: The Netherlands
Contact:

Re: PHP for beginners

Postby G-Brain » Sat Nov 17, 2007 10:09 pm

I will submit a tutorial.

Fergie1
Posts: 257
Joined: Sun Jul 15, 2007 2:22 pm
Location: UK

Re: PHP for beginners

Postby Fergie1 » Sat Nov 17, 2007 11:21 pm

You PMed me a while back about a Perl tut if that helps at all.


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 1 guest