Web Hosting Deals Holiday Logo Design Webcam Chat Website Header Templates Register domain Search Engine Optimisation Web Hosting
Go Back   Talk Mania Forum > Tutorials > PHP / Perl / Java / JavaScript / CGI Tutorials

PHP / Perl / Java / JavaScript / CGI Tutorials PHP / Perl / Java / JavaScript / CGI Tutorials Please do not use this Forum to advertise your site or to link to tutorials.

 Image
Buy Sell Downloads

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-28-2007, 02:39 PM
Base's Avatar
Senior Member
 
Join Date: Mar 2007
Location: North Yorkshire, UK
Posts: 121
Base is on a distinguished road
Send a message via MSN to Base Send a message via Skype™ to Base
The PHP baisics (#1)

Tutorial #1 - the PHP baisics.

Ok, so i am going to introduce you to PHP today.

PHP is the most expandable, easiest to learn, easiest to operate, and easiest to use web side programming language that exists to date.

Lets get into it!

All PHP documents start with this:

Code:
<?php
*NOTE you can also use <? but for the sake of ease, we are going to use the primary*

Ok, so now we need to put our code in!

Variables:

PHP, like all other programming languages, uses variables, these are little "blocks" which can hold any apla/numerical value you want them too.

The way to declare a variable is:

$ - This tells the server that the following word is a variable

name_of_variable - Supprisingly enough this is the name of the variable

= - Means that $name_of_variable is eaqual too >

"Variable contents in here" - What its going to be equal too

; - Telling the script that your now finished the statement *** You need to remember this, as you will often forget it, when you start learning***

So all together its:

Code:
 <?php
$variable = "My name is tom!";
?>
Ok, so now you will notice i used this : "?>"

This tells the server we have finished parsing that section of PHP.


Summing up the first part:

All scripts must start with <?php

All scripts must end with ?>

Displaying text and variables:


So from are part 1, we learnt how to declare a variable.

Now we are going to learn how too show the contents of that variable and other things:

The main command you use for showing text variables, or anything is

Code:
 echo
So lets say we wanted to put on our screen the following text

I am following a fantastic tutorial by Base, because he is just so ace?

We would put:

echo "I am following a fantastic tutorial by Base, because he is just so ace?";


So again with the end of this script we are using ";" to declare that we have finished parsing that perticular statement.

Now we are going to move onto somthing a little bit more complicated.


Code:
<?php

$head = "Dear Sir/Madam <br><br>";
$body = "It has come to my attention that you are looking for a PHP coder, i would be interested in taking up the position.
<br>
I started learning PHP following a set of simple tutorials from a site called Talk-Mania, and since then, i have improved my skills to the level at which i write programs for multi national organisations
<br>
<br>
Please send me a reply, if you would like to employ my bitching skills.";
$thanks = "<br><br> Yours most sincerely and respectfully <br><br> PHP Student.";

echo "$head $body $thanks";

?>
So!

That would put on your screen:

Dear Sir/Madam

It has come to my attention that you are looking for a PHP coder, i would be interested in taking up the position.
I started learning PHP following a set of simple tutorials from a site called Talk-Mania, and since then, i have improved my skills to the level at which i write programs for multi national organisations


Please send me a reply, if you would like to employ my bitching skills.

Yours most sincerely and respectfully

PHP Student

Which is rather cool.

Another thing you can do, is put variables in with other text so:

Code:
<?php
$name = "Base";

echo "$name is in fact god? $name has helped me become the man i am today, a true leg-end. Thankyou $name";
?>
So that would output:

Base is in fact god? Base has helped me become the man i am today, a true leg-end. Thankyou Base.

So you get the idea, you can put variables inside other things.

Another thing you can do is add variables that contain numbers together.

E.g.

Code:
<?php

$price = "5.21";
$VAT = "0.175";

$total = $price * $VAT;

$totalprice = $total + $price;

echo $totalprice;
?>
(The above is a VAT calculator)

That would echo:

6.12175

**Now for the people who doubt me, you may point out that i am not using variables set as integers, i will use them later on.**


Ok, so i will tell you now...

What we are going to do in this entire set of tutorials, we are going to build a content management system.

Hopefully it will have all the features you require here is a baisic outline of them.

User Log in/out
Post news
Change navigation bar
Edit users
Create users
Edit styles

All sorts of stuff baisicly.

Now in a normal content management system, users can log in and create a profile and things.

Howerver i have never found a practical use for it, so i am not including it, howerver if you would like me to include that in my tutorial, then ask!

Thanks very much and watch out for tutorial #2 coming in the next few days.


Cheers

Base

__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png
PointServ.co.uk - One of the UK's cheapest webhosting companies.
Reply With Quote
  #2 (permalink)  
Old 04-01-2007, 04:42 AM
Junior Member
 
Join Date: Apr 2007
Posts: 3
Julio Cesar is on a distinguished road
Good!!!

Excellent!!!!!!!
Reply With Quote
  #3 (permalink)  
Old 04-04-2007, 06:57 PM
Junior Member
 
Join Date: Mar 2007
Posts: 20
kraze101 is on a distinguished road
nice tutorial for the basics looking forward to reading the rest
Reply With Quote
  #4 (permalink)  
Old 04-28-2007, 09:52 PM
Junior Member
 
Join Date: Apr 2007
Posts: 16
quocnhan is on a distinguished road
thanks i learn some thing from this
Reply With Quote
  #5 (permalink)  
Old 05-01-2007, 04:37 AM
Junior Member
 
Join Date: Apr 2007
Posts: 20
logikal_one is on a distinguished road
Great help! We need more like this.
Reply With Quote
  #6 (permalink)  
Old 05-03-2007, 08:49 PM
Member
 
Join Date: Sep 2006
Location: Cyber Space, Uk.
Posts: 91
Nick is on a distinguished road
Send a message via AIM to Nick Send a message via MSN to Nick Send a message via Yahoo to Nick Send a message via Skype™ to Nick
For the vat calculator you could optimize the script by just multiplying it by 1.175. Also, you can use a $_REQUEST variable to make it slightly more dynamic.

PHP Code:
<?php

echo $_REQUEST['cost'] * 1.175;

?>
__________________
Nick - Coder/Designer
Reply With Quote
  #7 (permalink)  
Old 05-04-2007, 03:01 AM
Junior Member
 
Join Date: Feb 2007
Posts: 20
edrix is on a distinguished road
Man that is what i need
Reply With Quote
  #8 (permalink)  
Old 05-04-2007, 04:55 AM
Junior Member
 
Join Date: May 2007
Posts: 20
travmanx is on a distinguished road
I can't wait to see the rest of the tutorials. Very well explained!
Reply With Quote
  #9 (permalink)  
Old 05-16-2007, 02:52 PM
Junior Member
 
Join Date: May 2007
Posts: 18
orionmd is on a distinguished road
i learn some thing from this!! well done man
thx
Reply With Quote
  #10 (permalink)  
Old 05-18-2007, 12:36 AM
Junior Member
 
Join Date: May 2007
Posts: 20
phlop is on a distinguished road
Quote:
Originally Posted by Nick View Post
For the vat calculator you could optimize the script by just multiplying it by 1.175. Also, you can use a $_REQUEST variable to make it slightly more dynamic.

PHP Code:
<?php

echo $_REQUEST['cost'] * 1.175;

?>
I think he didnt use that becuase he is trying to show as many different commands as posible.

Reply With Quote
Reply

Bookmarks

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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +2. The time now is 01:43 AM.


Fake ID

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC8
Forums Copyright © Talk-Mania.com