Go Back   iGuides Webmasters and Business Talk > iGuides Tutorials > Development Tutorials
Register FAQ Rules Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)   Report Post  
Old 11-19-2007, 10:14 AM
iGuides Addict
 
Join Date: Oct 2007
Posts: 83
al-zabir is on a distinguished road
iTrader: (1)
Default Some basic tutorial for PHP beginners

Variables in PHP
Variables are used for storing a values, like text strings, numbers or arrays.
When a variable is set it can be used over and over again in your script
All variables in PHP start with a $ sign symbol.
The correct way of setting a variable in PHP:$var_name = value;


Let's try creating a variable with a string, and a variable with a number:

PHP Code:
<?php
$txt 
"Hello World!";
$number 16;
?>
Displaying variable in php is very easy. Here is an example ---

PHP Code:
PHP Code:
<?php 
$txt 
"Hello World!"
$number 16

echo 
$txt
echo 
$number
?>
Result:

Quote:
Hello World!16
Displaying variables with string in php is also very easy. Here is an example ---

PHP Code:
<?php  
$txt 
"Hello World!";  
$number 16;  

echo 
"$txt is text<br>$number is Number";  

?>
Result:

Quote:
Hello World! is text
16 is Number
You can use PHP and HTML together. For this you just use <? and ?> tag within those you will write your php code. But your page extention must be .php. Let's try the following example --


PHP Code:
<html> 
<head><title>Test page with php+html</title></head> 
<body> 

<?php 
echo "Welcome to test page"
?> 

</body> 
</html>
If..Else is a common condition function for php.

Structure of If..Else ( Single Condition )

Code:
Quote:
if(condition)
statement1;
else
statement2;
Example ( Single Condition )

PHP Code:
Code:
if($i==1) 
$i=$i+1; 
else 
$i=$i-1;
Structure of If..Else ( Multiple Condition )


i
Quote:
f(condition){
statement1;
..
...
statementn;
}
else{
statement1;
..
...
statementn;
}
Example ( Multiple Condition )


PHP Code:
if($i==1){ 
$i=$i+1
$j=2

else{ 
$i=$i-1
$j=3

For Loop is the mostly used loop function not only php but also any other language.

Structure of FOR LOOP:

Code:
Quote:
for(initialization; condition; increment/decrement)
{
statement1;
..
...
....
statementn;
}
Example of FOR LOOP:

PHP Code:
for($i=1$i<=10$i++) 

$a=$a+1
$n=$n+1

While loop in PHP:
==================

Structure:
=========
Quote:
intialization;
while(condition){
statement1;
statement2;
.
.
.
statementN;
loop factor;
}
Example:
=========
PHP Code:
$i=0;
while(
$i<=10){
echo 
"$i&nbsp;";
$i=$i+1;

Result:
=========
Quote:
0 1 2 3 4 5 6 7 8 9 10
Redirecting in PHP:
===============

Redirecting to any url from a php page is very easy task. Just a bit of use of a function is needed. Let's do it.

The following code will redirect user to the url "http://fahimgallery.freehostia.com"

Code:
<?
header('Location: http://fahimgallery.freehostia.com/');
?>
Note
Quote:
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
Adding value of two variables in PHP
============================

Code:
<?
$a=1;
$b=2;
$c=$a+$b;
echo $c;
?>
Result:
============================
Code:
3
Concating Variables in PHP:
=======================
Concating variables in PHP needs just a dot(.) between two variables

Code:

Code:
<?
$var1='Hello';
$var2=' ';
$var3='World';
$final=$var1.$var2.$var3;
echo $final;
?>
Result:

Quote:
Hello World
Source: iGuides.org Webmasters Talk
__________________
GamesVenture

Last edited by iGuides : 11-19-2007 at 11:16 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)   Report Post  
Old 06-13-2008, 02:18 PM
Newbie
 
Join Date: Jun 2008
Posts: 6
A. Williams is on a distinguished road
iTrader: (0)
Default

hey i think i already mentioned in one of my posts that w3schools.com is really good for the php.......if its not yours visit the above mentioned site.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:47 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0

Ad Management by RedTyger