|
| Web Hosting Deals | Holiday Logo Design | Webcam Chat | Website Header Templates | Register domain | Search Engine Optimisation | Web Hosting |
|
|||||||
| 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. |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
||||
|
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 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!"; ?> 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 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"; ?> 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"; ?> 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; ?> 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. |
|
|||
|
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:
__________________
Nick - Coder/Designer |
|
|||
|
I think he didnt use that becuase he is trying to show as many different commands as posible.
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|