HTML/Javascript

SES by business degree online promotion team.

Philippine Airlines International Flight schedules

Philippine Airlines International Flight schedules
Philippine Airlines International Flight schedules

Search This Blog

Saturday, August 28, 2010

PHP Beginner's guide






PHP BASIC TO ADVANCE

First thing before you can learn php script, install xampp first on your computer.
Note: you can download xampp installer from Apache Friends or, just type as “Apache Friends” as your keyword on google search engine then click search.

You will need the following as your primary tool
Notepad: Notepad2 4.1.24
Download at :http://www.flos-freeware.ch

you can choose one of the xampp installer:
download at apache friends:
xampp-win32-1.6.6a-installer
xampp-win32-1.7.3 php 5.3.1

To install xampp see from the first page link Installation XAMPP to run php


PHP Beginner's Guide
Variables on PHP

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 variables together, use the dot (.) operator:

code:
<?php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2;
?>

PHP Date()
<?php
echo date("Y.m.d");
echo "<br>";
echo date("Y-m-d");
?>
The output of the code above could be something like this:
2006/07/11
2006.07.11
2006-07-11

Using PHP Date - add to use Timestamp
The Syntax is:
mktime(hour,minute,second,month,day,year,is_dst)



One day to future just use argument of mktime():

The output of the code above could be something like this:
Tomorrow is 2006/07/12


CONDITIONAL STATEMENT
If Statement Example
<?php
$yourname = "peter";

if ( $yourname == "peter" )
{
echo "the value name is peter!";
}
echo "test variable value";
?>
output:
the value name is peter!test variable value


If/Else an Example
<?php
$number_three = 3;

if ( $number_three == 3 )
{
echo "The if statement evaluated to true";
}
else
{
echo "The if statement evaluated to false";
}
?>

<?php
$age = 10;

if ( $age == 10 )
{
echo "your age is equal to 10";
}
else
{
echo "your age is not equal to 10";
}
?>


PHP - Using Elseif with If...Else
$visitor = "Marian";
if($visitor == "Marian")
{
echo "You have a vistor, she's Marian!";
}
elseif($visitor == "Salome")
{
echo "You have a vistor, He is Salome!";
}
else
{
echo "You have another visitor not in my list JO!!";
}
?>


Here are the some site links that can help you to study php operators such:

Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Site Link, this can help you for the creating php operators:
highlight the one of the link, then paste it to the url browser
http://www.w3schools.com/php/php_operators.asp
http://www.codedcode.com/php/php-operators.asp


Basic PHP Computation using html table element

This sample code can help you to do the very basic type of creating computation on PHP.
If you have noticed two numbers placed inside a variable, then display the output using php code.
code to paste:

<?php
$doforaddition = 4 4;
$doforsubtraction = 10 - 5;
$doformultiplication = 100 * 2;
$dofordivision = 100 / 2;
$doformodulus = 5 % 2;

echo "<table border='1' align='center'>";
echo "<tr>";
echo "<td colspan='3' align='center'><b>Sample Basic Php Calculation</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Addition 4 + 4</td>";
echo "<td>".$doforaddition."</td>";
echo "<tr>";
echo "<td>Subtraction 10 - 5</td>";
echo "<td>".$doforsubtraction."</td>";
echo "<tr>";
echo "<tr>";
echo "<td>Multiplication 100 * 2</td>";
echo "<td>".$doformultiplication."</td>";
echo "<tr>";
echo "<tr>";
echo "<td>Division 100 / 2</td>";
echo "<td>".$dofordivision."</td>";
echo "<tr>";
echo "<tr>";
echo "<td>Modulus 5 % 2</td>";
echo "<td>".$doformodulus."</td>";
echo "<tr>";
?>

Output:





PHP Switch Statement

<?php
$destination = "Boracay";
echo "Traveling to $destination ";

switch ($destination)
{
case "Tacloban":
echo "It's a nice place, sunrise view start from the east of the city";
break;
case "Samar":
echo "Be government friendly";
break;
case "Biliran":
echo "A plenty of fish";
break;
case "Cebu":
echo "Meet new friends";
break;
case "Boracay":
echo "Many resort";
break;
}
?>

Display:
Going Boracay
Many Resort


Include & require functions

Note: or you can use for the require functions.
include.php

Display:
helloworld.php
nd


PHP round off a number


$number = number_format($number, 2);
echo $number; // equals "28.00"

$average = $totalrank_totaling / 3;
$average_rounded =round($average, 2);

echo $number;
echo "<br>";
echo $average_rounded;
?>

2 comments: