Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Website Design Forum


You are currently viewing our Website Design Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 12-28-2005, 04:08 PM Basic PHP Tut
Experienced Talker

Posts: 47
Trades: 0
Hi, got this basic tutorial from some forum
Quote:
The Basics Of PHP
Im not sure if there is already a basic tutorial here of PHP , i looked but never seen any (Sorry if there is) but anyhow let's get started

By reading this tutorial you should have the basic know how to execute small script's on your php enabled servers. Note that i will not be explaining how to set up a web server + php support.

What Does PHP Stand For?

PHP- Hypertext Preprocessor

Starting & Ending Tags

We start off by learning the 2 main tag's that you must never forget , that is the starting and ending tag's.

Starting
Code:

<?php

Ending
Code:

?>

Baisc Syntax

Now that you know about the starting & ending tag's , let's start with a basic script.
Code:

<?php echo "This is my first php script!"; ?>

so you have noticed echo , echo is simple, it output's the text "This is my first php script!" , now you must end this with a semicolon , why? the semicolon is a seperator and is used to distinguish one set of instructions from another.

Variables

Now that you know some basic syntax let's start working on variables , variables are ton's of fun and one of the most important part's of PHP.
Code:

<?php $myfirstscript = "This is my first php script!"; echo $myfirstscript; ?>

So you have noticed $myfirstscript , i made the variable $myfirstscript that hold's the string "This is my first php script!" . Then ofcourse just echo'd the variable which would output "This is my first php script!".

Comments

Comments are also another important thing not only in php but all languages , there used to disable any type of information inside them from actually executing with your script which ofcourse would likely cause error's.
Code:

//This is a comment /*This is a comment block*/

Condition Statements

Now these are fun to play with , they are used to execute certain code on a condition.
Code:

<?php $mybrowser = "Fire Fox"; if ($mybrowser == "Fire Fox") { echo " You are using firefox!"; } else { echo " You are not using firefox"; } ?>

So here i have set a variable equal to my browser then made a condition, if my browser is equal to firefox, output "You are using firefox" else (if your using something else) output "You are not using firefox" . Ofcourse this will not work untill i i add more to it but it give's you all a idea how condition statements work.

Looping

Looping is used for many many thing's , there are more then just one loop statement, ill explain how to do the "While Loop".
Code:

<?php $z = 1; while ($z <= 5) { echo $z; $z++ }

Again i made a variable named z with the value of 1 , then stated while z is less or equal to 5
Code:

while ($z <= 5)

output the value of z
Code:

echo $z

, increase z by 1
Code:

$z++

. Which would output 1-5 on your page. Simple isn't it?

Forms

Now im assuming you have some basic understanding of html, although i will give an example of the html form but i will not be explaining it.
Code:

<form action="form.php" method="post"> Name: <input type="text" name="name"> <input type="submit" value="Submit">

That's the html form , very simple. Now to the fun part.
Code:

<?php $name = $_POST["name"]; echo "Hello ". $name; ?>

Now here you have noticed something new and that would be
Code:

$_POST["name"]"

&
Code:

$_POST

is a variable already set by php , it recieved the information givin in the html form , notice the name="name" in the html form and ["name"] in $_POST.

Now this is the end of this small basic tutorial , you should now have the knowledge to execute simple script's on your server's.
pairbrother is offline
Reply With Quote
View Public Profile Visit pairbrother's homepage!
 
 
Register now for full access!
Old 12-31-2005, 12:32 PM RE: Basic PHP Tut
Junior Talker

Posts: 68
Trades: 0
Good topic for starters. One thing which i always note in most tutorials is optimization is not talked about.

Its the most critical part. Like the above code is using "(double quotes) for all the strings, but i'd rather use '(single quote) because its much faster and reduces the processing time.

For a script of 10 lines it doesn' tmatter. but as it becomes larer its really important.
jaswinder_rana is offline
Reply With Quote
View Public Profile Visit jaswinder_rana's homepage!
 
Reply     « Reply to Basic PHP Tut
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16714 seconds with 12 queries