Monday, July 4, 2011

PHP CODING

String Variables in PHP

String variables are used for values that contain characters.

In this chapter we are going to look at the most common functions and operators used to manipulate strings in PHP.

After we create a string we can manipulate it. A string can be used directly in a function or it can be stored in a variable.

Below, the PHP script assigns the text "Hello World" to a string variable called $*txt:


<*?php$txt="Hello World";echo $txt;?>

PLEASE Remove Firstly All Asterics *



Results:


Hello World



The Concatenation Operator

There is only one string operator in PHP.

The concatenation operator (.) is used to put two string values together.

To concatenate two string variables together, use the concatenation operator:


<*?php
$txt1="Hello World!";
$txt2="What a nice day!";echo $txt1 . " " . $txt2;?>

PLEASE Remove Firstly All Asterics *



Results:


Hello World! What a nice day!



The if Statement

Use the if statement to execute some code only if a specified condition is true.


<*html>
<*body>

<*?php
$d=date("D");
if ($d=="Fri") echo "Have a nice weekend!";?>

<*/body>
<*/html>

PLEASE Remove Firstly All Asterics *



The if...else Statementt

Use the if....else statement to execute some code if a condition is true and another code if a condition is false.


<*html>
<*body>

<*?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";?>

<*/body>
<*/html>

PLEASE Remove Firstly All Asterics *



The if...elseif....else Statement

Use the if....elseif...else statement to select one of several blocks of code to be executed.


<*html>
<*body>

<*?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";?>

<*/body>
<*/html>

PLEASE Remove Firstly All Asterics *



The PHP Switch Statement

Use the switch statement to select one of many blocks of code to be executed.


<*html>
<*body>

<*?php
switch ($x)
{
case 1:
echo "Number 1";
break;
case 2:
echo "Number 2";
break;
case 3:
echo "Number 3";
break;
default:
echo "No number between 1 and 3";
}
?>

<*/body>
<*/html>

PLEASE Remove Firstly All Asterics *



Multidimensional Arrays

In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on.


$*families = array
(
"Griffin"=>array
(
"Peter",
"Lois",
"Megan"
),
"Quagmire"=>array
(
"Glenn"
),
"Brown"=>array
(
"Cleveland",
"Loretta",
"Junior"
)
);

PLEASE Remove Firstly All Asterics *



Results:


Array
(
[Griffin] => Array
(
[0] => Peter
[1] => Lois
[2] => Megan
)
[Quagmire] => Array
(
[0] => Glenn
)
[Brown] => Array
(
[0] => Cleveland
[1] => Loretta
[2] => Junior
)
)



The for Loop

The for loop is used when you know in advance how many times the script should run.


<*html>
<*body>

<*?php
for ($i=1; $i<=5; $i++)
{
echo "The number is " . $i . "
";
}
?>

<*/body>
<*/html>

PLEASE Remove Firstly All Asterics *



The $_GET Function

The built-in $_GET function is used to collect values from a form sent with method="get".

Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.


<*form action="welcome.php" method="get">
Name: <*input type="text" name="fname" />
Age: <*input type="text" name="age" />
<*input type="submit" />
<*/form>

PLEASE Remove Firstly All Asterics *



The $_POST Function

The built-in $_POST function is used to collect values from a form sent with method="post".

Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.


<*form action="welcome.php" method="post">
Name: <*input type="text" name="fname" />
Age: <*input type="text" name="age" />
<*input type="submit" />
<*/form>

PLEASE Remove Firstly All Asterics *



PHP ADVANCED--CLICK ME


THANK YOU