Search This Blog

Wednesday, February 10, 2010

වෙබ් පිටු දේශීයකරණය කිරීම

වෙබ් යෙදුමක් හෝ අඩවියක භාශාව වෙනස් කිරීම ගැන තමයි අද අපි සලකා බලන්න හදන්නේ. අද නිදහස් මෘදුකාංග බොහෝමයක් නිර්මාණය වෙන්නේ මේ පහසුකමත් ඇතුලත් කරලා.. විශේෂයෙන්ම බොහෝමයක් වෙබ් යෙදුම් නිර්මාණය වෙන්නේ මේ පහසුකම සහිතවයි. ඊට හේතුව තමයි ඒවාට සමාජයේ උනන්දුවක් දක්වන වැඩි පිරිසගේ දායකත්වය ලැබෙන නිසා එය පහසුවෙන් තමන්ට අවශ්‍යය ආකාරයට සකසා ගැනීමට ඔවුනට පහසුව සැලසීම. මීට අමතරව එවන් හැකියාවක් තීබීම එම මෘදුකාංගය භාවිත කරන පිරිස වැඩි කරගැනීමටත් ඉවහල් වෙනවා..

අද මම මේ පහසුකම වෙබ් යෙදුමක හෝ අඩවියක PHP භාවිත කර නිර්මාණය කරන හැටි සරල විදියට පෙන්නන්නයි ලැහැස්තිය..

BELOW IS THE FOLDER STRUCTURE I'AM USING TO THIS WEB SITE

/ - the_web_app
    |_ index.php
    |__ lang <folder>
        |_english.php
        |_ sinhala.php

lang/english.php ගොනුවේ තමයි අපි අදාල වෙබ් පිටුවේ දර්ශනය කිරීමට බලාපොරොත්තු වන ඉංග්‍රීසි භාශා වදන් තියෙන්නේ.
ඒ අයුරින්මයි සිංහල වදන් තිබෙන්නේ lang/sinhala.php ගොනුවේයි.

පහතින් ඇත්තේ index.php ගොනුවේ කේතයි
-------------------------------------------------------------------------------------
<?php

session_start();

$_SESSION['localization']['lang']= 'english';
/// deaul language is english selected

if(isset($_POST['btnChangeLang'])){
//if user selected to change lanuage
$_SESSION['localization']['lang']= $_POST['cmbLang'];
}
require 'lang/'.$_SESSION['localization']['lang'] .'php';

?>

<html>
<head>
<title>Application localization sample</title>
</head>
<body>
<form name="frm1" method="post" action="index.php">
<table width="60">
<tr>
<td colspan="2"><?php echo($APP_STRINGS['lang_opt']['display']);?></td>
</tr>
<tr>
<td width="20">
<select name="cmbLang" id="cmblang" >
<option value="sinhala"><?php echo($APP_STRINGS['lang_opt']['select_opt']['sinhala']); ?></option>
<option value="english"> <?php echo($APP_STRINGS['lang_opt']['select_opt']['english']); ?> </option>
</select>
</td>
<td width="40">
<input type="submit" value="<?php echo($APP_STRINGS['lang_opt']['button']); ?>" id="btnChangeLang" name="btnChangeLang" />
</td>
</tr>
</table>
</form>
</body>
</html>

-----------------------------------------------------------------------------------------------
lang/english.php

<?php

$APP_STRING['lang_opt']= array(

"button"=
>"Change Language",
"select_opt"=
> array("sinhala"=>"Sinhala","english"=>"English"),
"display"=
>"Select a Language option and hit '\"Change Language\" button "
);

?
>

------------------------------------------------------------------------------------------------
sinhala.php


<?php

$APP_STRING['lang_opt']= array(

"button"=
>"භාශාව වෙනස් කරන්න",
"select_opt"=
> array("sinhala"=>"සිංහල","english"=>"ඉංග්‍රීසි"),
"display"=
>"මුලින් භාශා විකල්පය තෝරා '\"භාශාව වෙනස් කරන්න\" බොත්තම ඔබන්න "
);

?>
------------------------------------------------------------------------------------------------

Saturday, August 1, 2009

Make Connections to Mysql Database

ආයුබෝවන් වාසනාවන් !!!

අද මට හිතුනා සිංහලෙන් ලියන්න කියලා. අපි අද ඉඳලා බලන්න හදන්නේ, කොහොමද mysql දත්ත ගබඩාවක අපිට ඕනෑ කරන ආකාරයට දත්ත සකසන්නේ කියලා. ඒ ඔක්කෝටම කලින් අපි අද බලමු mysql දත්ත ගබඩාවකට වෙබ් පිටුවක ඉඳලා

Thursday, July 16, 2009

How to write Switch Case statement in PHP

HI all,

Here we can today learn how we could write a switch case construct in php. You know this statement we called it as conditional structure. that means this switch is used to do something if conditions provided are satisfied. this is basically equal to the if - else if - else statement.

here is the syntax for the Switch statment;

switch($var)
{
case "1":
echo"it is one";
break;
case "2":
echo"it is Two";
break;
case "3":
echo"it is Three";
break;
default:
echo "defaul Value ";
break;
}


Tuesday, May 5, 2009

Loop constructs in PHP

hello Dear,

Firs sorry for waiting long time to post this since my last post. I was having lot of works to complete in last few days. herewith today we gonna look at loops in php

as in other languages php has loop/iterative construct. those loop construct are
  • for
  • while
  • do .. while
  • foreach
here is the sample for each of the above loops.

for loop ..

for($i=0; $i < 10; $i++)
{
echo ($i . '< br />');
}

//----------------------------------------------

While Loop

while($row=mysql_fetch_array($result))
{

echo ($row[0] . "< br />");

}

//----------------------------------------------

Do While loop

$i=0;
do
{
$i++;

echo ("the no is:" . $i . "< br />");

}
while($i<5);


//------------------------------------------------

foreach loop

$persons= array("name"=>"mcDonald","city"=>"torento","country"=>"USA");

foreach($item=keys($persons ))
{
echo($persons[ $item] . "< br />");
}

we will try the case statement in next lesson and i'll stop @ here thanks gys n galls

Thursday, April 16, 2009

arrays in PHP

To day We will look @ arrays in php


in PHP we can find two types of arrays that one is array that we usually used

with numeric indexed, and another one is associative arrays. this type of arrays

also behave as same as usuall arays we used to.. only difference is we can use alphanumeric key index.



You can understand this with following example..


normally array is key value paired .



ex1:

[0] => 456

[1] => 3456

[2] => 566

[3] => 70


-------------------------------------------


ex 2:


["name"] => "Mc.Donald"

["ID"] => 1234567889

["SSN"] => "239898K"

["Country"] => "Australia"

["age"] => 45


in first example array index keys are numeric values {0,1,2,3} but in example 2 it is an alphanumeric values {name,ID,SSN,Country,age}



How can create and access the arrays in PHP

arrays can be created and accessed in normall way how we do in other languages only difference is we dont specify the type of the values that holds by the array

see below example how we create array.


$Marks= array(0=>12,1=>34,2=>50,3=>60,4=>45); this array definition is also same as below definition..

$MarksII= array(12,34,50,60,45); // with this style index is autogenerated.



echo $Marks[0]; // output is 12

echo $MarksII[0]; // output is 12


now we see ho we can create an associative array ..

this is also same as normal array definition.



$StudentsMarks = array("kamal"=>30,"amal"=>34,"nimal"=>50,"sunil"=>20); // this holds an marks of each stdents for a particular subject

how we can print marks of a given student.



echo $StudentsMarks["amal"]; /// this wil echoes the marks of student amal. output is 34

echo $StudentsMarks["sunil"]; /// this wil echoes the marks of student sunil. output is 20



when we working with array we have to loop through the array. how we can loop associative array

is like this...



foreach($key=key($StudentsMarks))

{

echo "marks of $key : $StudentsMarks[$key]<>";


}


this will prints an out put like below...



marks of kamal : 30

marks of amal : 34

marks of nimal : 50

marks of sunil :20



i think you got some idea about arrays in PHP and im retain @ here.. we'll meet again with onother lesson

thank you..

Saturday, April 4, 2009

PHP lesson II

Hi all ,
Today we gonna have a look at data types and variable in PHP

is there any data type in php? have you ever noticed that? like other programming languages we don't mention the data type of the variable wehen it declares huh..?
ex..
in C# ig we want an integer variable we declare it like this
int i=0;
but with PHP we dont mention it so. what we do is we simply use
$i=0;

why we can do this, how php going to identify the type of the variable then.. does php has no data type ? we have to find answers fo these questions rite?

the reason for this defference is "typing" what is typing means.. while other laguages use "strong type" php is gonna use "weekly type". basically in a higher level PHP has scalar type only. but behid the screen you can find couple of data type those are integer,string,double. PHP identifies the data type depending on the variable context.. you can see this with the following simple script
$i=10; // this will be integer type
$f=250.00; //this is a double
$str="Hi i'm string"; // this is string type
$s='im too string '; // This is also a string
$c='a'; // This is also a string

/*to see the data type of each variable we can use getType(); function*/

echo( getType($i));
echo "<br/>"; ;

echo(getType($f));
echo "<br/>";

echo( getType($str));
echo "<br/>"; ;

echo( getType($s));
echo "<br/>"; ;

echo(getType($c));
echo "<br/>";

?>

The out put will be like this
integer
double
string
string
string

try this.. hope you got to know something new..
will meet with another lesson later
bye...

:-)

Friday, April 3, 2009

හිංගලෙන් ලියන්න හිතුනා

හිංගලෙන් කතා කරමු

ම‍ට අද නිකමට හිතුනා මොනවා හරි සිංහලෙන් ලියන්න ඕන කයලා. ඉතින් ඔන්න ලිව්වා. ඔයාලා කාට හෝ අදසක් තියෙනවා නම් මේ අදහසට ප්‍රතිචාර එවන්න. සුදුසු මාතෘකාවක් අරන් අපි සංවාදයක් ගොඩ නගමු..

එහෙනම් මම මෙතනින් නවතිනවා.. බොහෝම ස්තූතියි.