Skip to main content

PHP Variables, Statements leh Operators hman dan


     PHP hi application tam tak, hmanrim leh lian thiam tak takah hman theih a ni a. Tin, Database Extention tam tak a neih avangin database lian tham tak tak Oracle, MySQL, MSSQL etc te nen awlsam te a hman kawp mai theih a ni bawk. Tin, XML thlenga a support vek avangin XML hman theihna applications ang chiah PHP module awlsamtein developer tan siam zung zung theih a ni. Tin, Manual mumal tak a neih vangte, developer tam tak awmkhawmna a nih vang te leh, man awm lova awlsamtea neih theih mai a nih avang hian web developer tam tak chu PHP-ah hian a ni telin an insawn reng bawk a ni.

HTML-a PHP dahdan (Embedding)
CGI scripts ang lo takin PHP hi chu HTML pangaiah awlsam tein dah tel mai theih a ni. Heng PHP script kan dah te hi abul tanna leh tawpna tags a bik tak hmangin daidan mai theih a ni a. Chu chu PHP interpreter khan a lo chhiar thei mai thin a ni. A hnuaia mi ang hian

<?php
PHP code hetah hian;
?>

Tin, Awlsam leh tawi zawk a hnuaia mi ang hian I hmang thei bawk a.

<?
PHP code hetah hian;
?>

A chunga kan thil hmuh hi eng nge a hnathawh chiah hre turin a hnuaia mi ang hian HTML leh PHP kan dahkawp anga.

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>CHHURA</title>
</head>
<body>
<h4>Q. Mizo thawnthua Nahaia, Unaupa kha tunge ni?</h4>
<?php
//A hnuaia mi ang hian Output pe turin PHP script kan siam anga
echo '<p>A: <i>Chhura</i></p>';
?>
</body>
</html>

Note: PHP-ah comment kan ziah dawnin, // emaw, #, C style /*……… */ ang chi te hman theih a ni.

A chunga I script siam khi local web root C:\apache2triad\htdocs\test ah test.php tiin han save la. Web Browser atangin http://localhost/test/test.php tiin han point la a hnuaia mi ang hian a lo lang ang a.


A chunga PHP page I hmuh hi View  ah kalin a source han en teh, a hnuai a mi ang hian PHP tags awm tawh loin HTML ngai ngai kha I hmu tawh thung ang.

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>CHHURA</title>
</head>
<body>
<h4>Q. Mizo thawnthua Nahaia, Unaupa kha tunge ni?</h4>
<p>A: <i>Chhura</i></p></body>
</html>


Browser atanga test.php en I tum chiah khan Apache web server khan I ngenna chu a lo hmu nghal a, script lo awma chu PHP hnenah hlanin, PHP chuan <?php ………… ?> kara code awm chu lo chhiarin atul dan anga thlak thlengin result output (Valid HTML) a rawn pe a. Chu chu Web Server-ah thawn let lehin web server chuan client-ah a rawn thawn chhawng ve leh a. Chu chu kan browser hmang khan awmze neiin kan lo hmu thei ta a ni.

Note: PHP hi interpreted language a ni a. Compiled language (Like C, C++, Java) a ni lo. Compiled language chuan I ASCII code te binary form-a lo thlak thlengtu turin I language hman a zirin compiler hranpa a mamawha, I program code te chu compiled hmasak phawt a nih loh chuan I program chu run theih a ni lo ang. Interpreted language erawh chu a nih ang ang khan run mai theih a ni a. chawp leh chilhin language interpreter khan lo chhiarin a nihdan tur angin hna a thawhtir nghal mai a ni. Tin, Compiled language angina, thil hote code thlakthleng I neih avangin a hranpaa compiled nawn kher a ngai lova, chu chuan I hnathawh nasa takin a tichakin hun a duhrei loh phah ang. Amaherawhchu, Compiled code erawhin hna a thawk chak zawng thung a, hei hi a chhan chu, Interpreted language angin hman apianga compiler-in codechhiar nawn kher a ngaih tawh loh vang a ni.

VARIABLES hmanna
Eng programming language-ah pawh variables tangkai zia chu kan hria anga, programming language siamtu pawimawh tak a ni ringawt mai. Variables chuan Number ang chi leh Number kher lo, data hrang hrang a dahtha (store) thei a ni. Heng Variables te hi program hman laiin tihdanglam mai theih a ni bawk a. Tin, heng variables te hi Operators hmanga khai khin theih a ni bawk.

PHP-ah hian variable types chi hrang hrang hman theih a ni a. Booleans, integers, floating point numbers, strings, arrays, objects, resources, and NULLS-te hi hman vek theih a ni.

Variable reng reng chuan hming neiin, dollar sign ($) hmanga tan vek a ni. Tin, variable hming chu letter emaw underscore hmangin emaw tan zel tur a ni. Entirnan: $pawngi, $PAWNGA, $_LAIBATA te hi variable siam dan dik a ni a. Chutihlaiin $123, $98degree tih ang te hi variable siam dan dik lo a ni.

PHP variables te hi case-sensitive a ni. CHumi awmzia chu $awle, $Awle, $AWLE tih hi variable hrang vek a ni.

A hnuaia mi ang hian PHP variable hnathawh dan chu en ila.

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>CHHURA</title>
</head>
<body>
<h4>Q. Mizo thawnthua Nahaia, Unaupa kha tunge ni?</h4>
<?php
//A hnuaia mi ang hian Output pe turin PHP script kan siam anga
//variable kan siam anga
$chhanna = 'Chhura';

//Tunah output kan siam ve thung ang
echo "<p>A: <i>$chhanna</i></p>";
?>
</body>
</html>

A chungah hian variable pakhat $chhanna tih chu string value nei turin siam a ni a. Ti chuan echo hmangin kan variable siam chu browser-ah kan en leh ta a ni.

VARIABLES-a form input lo dahthat dan
Form chu website-a user te nena kan indawr theihna awlsam ber leh rang ber te zing a mi a ni a. Form hmangin nangmah rawn dawrtu chuan thil a rawn zawt thei che a, tin I products chung changah te comment a rawn pe thei a ni. PHP chuan awlsamtea form data te lo chhiar thei turin variables-ah data te chu dahthat mai theih a ni. A hnuaia form entirna hi en la.

<html>
<head>
<title>CHHURA</title>
</head>
<body>
<form method="POST" action="form.php">
<input type="text" name="hming" size="20"><input type="submit" value="Send"></p>
</form>
</body>
</html>


A chunga HTML code-a thil pawimawh kan hmuh chu <form> tag hi a nit a a. Chutah chuan attribute pahnih method  leh action kan hmu a, method chuan engtia form chu thawn turnge tih (POST) a ti chiang a, action ve thung chuan kan form chu khawia thawn tur nge (form.php) tih a rawn tichiang ve thung. A chunga kan hmuh ang hian kan form chu form.php-ah bawk thawn tur a nih avangin form.php ah chuan a hnuaia mi ang hian PHP script kan siam anga.

<?php
//form atanga thil rawn thawn chu a hnuaia mi ang hian variable hmangin kan
//lo dah tha ang
$hming = $_POST['hming'];

//Output kan print anga
echo "Hei hi I type: <b>$hming</b>";
?>

I thil siam chu a hnathawh hre turin form-ah chuan ektum tih han type la, send tih chu han click teh le. Browser-ah chuan Hei hi I type: ektum” tih a lo lang mai ang.

Form hmanga PHP script-a thil kan post reng reng chu PHP container variable bik tak mai, $_POST hmangin chawp lehchilhin hmuh mai theih a ni ta a ni. Tin, $_POST aiah hian duh chuan $_GET hman theih a ni bawk.


DATA TYPES THENKHATTE:
Programming Language reng reng hian variables data type chi hrang hrang an nei vek a. Chuvangin PHP pawh hian variable data type hrang hrangte chu a kal kan thei bik lo a. numeric hote atanga arrays leh objects thlengin a nei ve vek a ni. A hnuaiah hian data type pali lek ziahlan a ni a.

Data Type
Hrilhfiahna
Entirna
Boolean
Hei hi chuan variable chu a dik leh dik loh a tichiang ringawt a ni.

$yes = true;
Integer
Integer chu a hnuaia number ang chi- 23, -41, 300, emaw 1

$parakum = 44;
Floating-point
Floating point chu fraction number ang chi 12.3, 323.235432 te hi

$khawlumdan = 32.65;
String
String chu thumal a indawta rem ti ila a ni mai awm e. Entirnan- ‘b’, ‘abc’, ‘Khuma’ tih te hi a ni a. PHP ah string kan variables value-ah kan dahin double quotes(") emaw, Single quote(')in kual khung zel tur a ni.

$hming = 'chhura';

Programming language tam berah chuan variables reng reng hi a type ziahlan hmasak zel a ngai a, PHP ah erawh chuan ziah hran ngai lovin amah leh amah a lo inthliar mai thei a ni.

Variable-a data type hrang hrangte zawnchhuahdan
PHP variable I siamte chu eng type nge tih I hriat chhuah duh chuan gettype() function hmangin awlsamtein I hre mai thei a ni.
A hnuaia entirna hi en la:

<?php
//variable-te kan siam anga
$yes = true;
$kum = 39;
$hming = 'Kunga';
$vawt = 56.3;

//Tunah eng type nge a nih hlawm kan en ang

//String la chhuak turin
echo gettype($hming);

//boolean la chhuak turin
echo gettype($yes);

//integer la chhuak turin
echo gettype($kum);

//double la chhuak turin
echo gettype($vawt);
?>

PHP hian variable te chu eng type a mi nge an nih thliar hrang turin function bik a nei a. A hnuaia table hi en la
Function
An hnathawh
is_bool()
Variable chu Boolean a nih leh nih loh a en fiah a
is_string()
Variable chu string a nih leh nih loh a en fiah a
is_numeric()
Variable chu Numeric String a nih leh nih loh a en fiah a
is_float()
Variable chu floating point number a nih leh nih loh a en fiah a
is_int()
Variable chu integer a nih leh nih loh a en fiah a
is_null()
Variable chu NULL a nih leh nih loh a en fiah a
is_array()
Variable chu array a nih leh nih loh a en fiah a
is_object()
Variable chu object a nih leh nih loh a en fiah a


STRING VALUES-a HRIATTUR THENKHATTE:
String Variable I siam zawh hnuah I variable siam chu echo hmangin I en dawn ta a. variables hming I vuahte chu double quotes hmanga I kual khung a nih chuan, chawp leh chilhin a value I siam hmangin a inthlak thleng nghal ang a. Amaherawhchu single quote hmanga I kualkhung a nih chuan a ngai ngaiin output a rawn pe mai dawn a ni. Chutiang bawkin variable value I pek pawhin a nit ho a ni.  A hnuaia entirna hi en la-

<?php
$name = 'Hminga';
$pro = 'Engineer';

//A hnuaia mi hian  "Hminga chu Engineer a ni" tih a rawn pe ang
$profile = "$name chu $pro a ni";

//A hnuaia mi ve thung hi chuan "$name chu $pro a ni" tih a ngai ngaiin a rawn pe ang
$profile = '$name chu $pro a ni';
?>

Tin, I variable siama string chuanin quotes a neih chuan backslash(\) hmangin escape zel tur a ni. A hnuaia entirna hi en la:

<?php
//a hnuaia mi hian error a pe ang
$diklo = 'Ha'n sawi hmiah la';

//A hnuaia mi hi a dik
$dik = 'Ha\'n inbawrti vel ila';
?>

NULL CHUNGCHANGA HRIATTUR THENKHATTE:
PHP 4.x chinah variable ruak ringawt atan data type thar NULL chu hman theiha siam a ni a. NULL data type hi a bik taka siam a ni a. A awmzia chu variable value nei lo tihna a ni. NULL hi variable value nei lo atangin a lo awm a. Tin, unset function hmangin variable value nei tawh pawh NULL pechhuak turin siam theih a ni bawk. A hnuaia entirna hi en la:

<?php
//A hnuaia mi hian NULL a rawn pe ang
echo gettype($yes);

//Value kan pe anga
$yes = 'Nghaka';

//Tunah a type kan check leh anga STRING a rawn pe thung ang
echo gettype($yes);

//unset() hmangin kan variable chu deinitialized ang
unset($yes);

//Tunah kan variable siam chuan NULL a rawn pe leh ang
echo gettype($yes);
?>

OPERATORS HMANDAN LEH VARIABLES KHAIKHIN DAN
Variables chu programming language sakna tur atana a ruhrel chu a ni a. Chutihlaiin operators chu chung ruhrel hrang hrangte char zawmtu kilh zawmtu tiin kan sawi thei ang. PHP chuan operators hrang hrang 15 a nei a. A hnuaia table hi en la.

Operator
An hnathawh
=
Assignment
+
Belhna
-
Paihna
*
Puntirna
/
Semna (a chuang awm)
%
Semna (A chuang awm lo)
.
String zawmna
==
Hlutna intluk
===
A hlutna leh a data type in ang vek
!==
A hlutna leh a data type in ang lo vek
<> or !=
In ang/tluk lo
< 
Aia tlem
<=
Aia tlem emaw intluk emaw
> 
Aia lian
>=
Aia lian emaw intluk emaw
&&
Logical AND (khaikhina a dik vek chuan True)
||
Logical OR (Eng ber emaw a dik chuan True)
xor
Logical XOR (Dik vekin False, engmaw ber chauh dikin True)
!
Logical NOT (a nih lohin True)
++
Pakhat belh
--
Pakhat paih

STRING OPERATORS:
String pahnih zawm(concatenate) tur chuan, string pahnihte inkarah khan dot (.) dah mai tur a ni. Hetiangin:

<?php
$yes = 'Mawi';
$domain = 'mizosoft.net';

//dot(.) hmangin a chunga variable pahnih hi kan zawm ang
$zawmna = $yes . '@' . $domain;
?>

A hnuaia mi ang hian a rualin dot(.) leh = hman kawp theih a ni.

<?php
//string kan siam anga
$me = 'mizo';

//. and =
$yes .= 'ram';

//Yes hlutna tur chu "mizoram" a lo ni tawh ang
?>

COMPARISON OPERATORS:
Tunah chuan variables kan siamte in an lohna leh inthlauhna hre turin PHP comparison operators engpawh I hmang tawh mai dawn a ni.

<?php
//Variable thenkhat kan siam anga
$mean = 29;
$median = 40;
$mode = 29;

// < (tlem zawk) operator kan hman hian vei lam chu a ding lam aia
// a tam zawk chuan 'true' tih out put a rawn pe ang
//A hnuaiah hian "true" tih result kan hmu ang
$result = ($mean < $median)

// > (tlem zawk) operator kan hman hian vei lam chu a ding lam aia
// a tam zawk chuan 'true' tih out put a rawn pe ang
//A hnuaiah hian "False" tih result  a rawn pe ang
$result = ($mean > $median)

// <= (tlem zawk emaw intluk emaw) operator kan hman hian vei lam chu a ding lam aia
// a tlem zawk emaw intluk emwa chuan 'true' tih out put a rawn pe ang
//A hnuaiah hian "False" tih result  a rawn pe ang
$result = ($median <= $mode)

// >= (tlem zawk emaw intluk emaw) operator kan hman hian vei lam chu a ding lam aia
// a tam zawk emaw intluk emwa chuan 'true' tih out put a rawn pe ang
//A hnuaiah hian "True" tih result  a rawn pe ang
$result = ($mean >= $median)

// == (intluk emaw in ang) operator kan hman hian vei lam chu a ding lam nen
// a intluk chuan 'true' tih out put a rawn pe ang
//A hnuaiah hian "True" tih result  a rawn pe ang
$result = ($mean == $mode)

// != (intluk lo emaw in ang lo) operator kan hman hian vei lam chu a ding lam nen
// a intluk loh chuan 'true' tih out put a rawn pe ang
//A hnuaiah hian "False" tih result  a rawn pe ang
$result = ($mean != $mode)
?>

Comparison in result a rawn pek chu a tlangpuiin Boolean a ni thin a chu chu True or False emaw zawk zawk a ni.

=== OPERATOR
PHP 4.0 atanga hman theih tura siam chhuah comparison operator pawimawh tak mai pakhat chu === operator hi a ni a, he operator hian variable pahnih te hlut zawng leh an data type in an leh an loh a khaikhin nghal a ni. A hnuaia mi hi en la:


<?php
//Variable pahnih tunah kan siam anga
$str = '15';
$int = 15;

//==(intluk) operator hmanga kan tih chuan True a rawn pe ang
//A chhan chu variable pahnih ten hlut zawng in ang an neih vangin
$result = ($str == $int);

// a hnuaia mi hian False a rawn pe thung ang
// A chan chu hlut zawng in ang mahse an data type a in ang lo a
//Pakhat string a nih laiin pakhat integer type a ni daih thung
$result = ($str === $int);
?>

LOGICAL OPERATORS
A hmalam table-a kan hmuh tawh angina PHP hian Logical Operators pali a nei a, chungte chu – logical AND, logical OR, logical XOR leh logical NOT. A hnuaiah hian a hnathawh dan tlem ziah lan a ni.
<?php
//variables thenkhat kan siam anga
$user = 'mizo';
$pass = 'tlangval';
$saveCookie = 1;
$status = 1;

//logical AND
//khaikhinna kan siam zawng zawng chu a dik vek chauhin True tih a rawn pe ang
//A hnuaiah hian True tih result a rawn pe ang
$result = (($user = 'mizo') && ($pass = 'tlangval'));

//logical OR
//khaikhinna kan siam eng pawh a dik chuan True tih a rawn pe ang
//A hnuaiah hian False tih result a rawn pe ang
$result = (($status < 1) && ($saveCookie == 0));

//logical NOT
//khaikhinna kan siam chu a dik loh chauhin True tih a rawn pe ang
//A hnuaiah hian True tih result a rawn pe ang
$result = !($saveCookie == 1);

//logical XOR
//khaikhinna kan siam zawng zawng chu a dik vek chuan False tih a rawn pe ang a
//khaikhinnaa pakhat zawk zawk a dik chauhin True a rawn pe ang
//A hnuaiah hian False tih result a rawn pe ang
$result = (($status == 1) XOR ($saveCookie = 1));
?>

Auto-Increment leh Auto-decrement operators
Auto-increment operator chuan variable engpawh amah zawmtu a piang chu pakhat(1) in a belh zel thin. Chutiang bawkin auto-decrement operator chuan pakhat(1) a paih ve thung. A hnuaia entirna hi en la.

<?php
//variable pakhat $avaiin tih a hlut zawng 15 nei kan siam anga
$avaiin = 15;

//tunah auto-increment (++) operator kan belh ang
$avaiin++;

//$avaiin hlut zawng tur chu 16 a lo ni tawh ang
?>

auto-decrement operator chuan a chunga mi letling chiahin hna a thawk vet hung
<?php
//variable pakhat $avaiin tih a hlut zawng 15 nei kan siam anga
$avaiin = 15;

//tunah auto-decrement (--) operator kan belh ang
$avaiin--;

//$avaiin hlut zawng tur chu 14 a lo ni tawh ang
?>

Heng operator te hi loop-ah loop counter hlut zawng update turin hman fo thin a ni.
Note: A chunga operator kan ziahlan te hi statement khata hmankawp an nihin hnathawk hmasa zawktu an awm zel a, chutiang indawt dan (precedence) chu a hnuaia mi ang hi a ni.

(1) '!' '++' '--'
(2) '*' '/' '%'
(3) '+' '-' '.'
(4) '<' '<=' '>' '>='
(5) '==' '!=' '===' '!=='
(6) '&&'
(7) '||'
(8) '?' ':'

A chunga precedence kan ziahte hi statement khat chungah kan hmang a nih chuan bracket hmanga kan hmanna chinin a khawih variable te nen kualkhung zel a tha a ni. Entirnan: 10*10+1 in a pek chhuah chu 101 a ni a. 10*(10+1) in a pek chhuah hlut zawng chu 110 a ni daih thung.


CONDITIONAL STATEMENTS LEH LOOPS
Conditional statement-ah chuan kan thil tihduha chu a dik leh dik loh enfiah turin action chi hrang hrang kan siam thei a ni.

If() Statement
PHP-a conditional statement awlsam ber chu if() a ni kan ti thei ang. A hnuaia mi ang hian:
<?php
if(conditional test)
{
     statement;
}
?>

Entirnan:

<?php
if($age <= 20)
{
     echo ‘Very young’;
}
?>

A chungah hian if() in a ken tel $age <= 20 kan hmu a, $age hlutna chu 20 aia a tam zawk emaw a intluk emaw a nih chuan ‘Very young’ tih hi a rawn tilang mai dawn a ni.
     Tin, if() bakah hian PHP chuan if-else() statement a la nei leh a.
<?php
if(conditional test)
{
     hei a thawk ang;
}
else
{
     hei a thawk ang;
}
?>

Entirnan:
<?php
if($age <= 20)
{
     echo ‘Very young’;
}
else
{
     echo ‘upa ve tawh’;
}
?>

Tin, PHP chuan thil engemaw zat khai khin nan if-elseif-else() a la nei cheu va. Hei hi chuan thil pakhat a endik a, a dangah a pakai a, chutiangin a tul dan angin action a la ta thin a ni.

<?php
if(conditional test 1)
{
     hei a thawk ang;
}
elseif(conditional test 2)

{
     hei a thawk ang;
}
.
.
.
elseif(conditional test n)

{
     hei a thawk ang;
}
else

{
     hei a thawk ang;
}
?>

Entirnan:
<?php
if($district == 'Champhai')
{
     $capital = 'Champhai';
}
elseif($district == 'Aizawl')
{
     $capital = 'Aizawl';
}
if($district == 'Lunglei')
{
     $capital = 'Lunglei';
}
if($district == 'Kolasib')
{
     $capital = 'Kolasib';
}
else
{
     $capital = 'Hriat loh';
}
?>

Switch() Statement
If-else() aia hman thin pakhat chu Switch-case() statement hi a ni. An hnathawh leh tihdan pawh a in ang vek tep a ni. Switch() statement-ah chuan case() hrang hrang te a endik hnuah a duh ang a hmuh loh chuan default ah a kal nghal mai thin a ni. A hnuaia switch statement kal dan phung hi en la.

<?php
switch(condition variable)
{
     case result 1:
          hei a ti ang;
     case result 2:
          hei a ti ang;
     .
     .
     .
     case result n:
          hei a ti ang;
     case default:
          hei a ti ang;
}
?>

Entirnan:
<?php
switch($district)
{
     case 'Champhai':
          $capital = 'champhai';
          break;
     case 'Aizawl':
          $capital = 'Aizawl';
          break;
     case 'Lunglei':
          $capital = 'Lunglei';
          break;
     case 'Kolasib':
          $capital = 'Kolasib';
          break;       
     default:
          $capital = 'Hriatloh';
          break;                 
}
?>
Heta break hnathawh ber chu case() pakhatah duh ang a hmuh tawh chuan a dawtah kal tawh lovin switch chu a kalsan tawh thin. Case zawng zawngah duh ang thil a awm loh chuan default ah a kal mai thin a ni.

Conditional Statement chhunga statement dang awm chhawng (Nested)
Condition engemawzat a chang chuan dahkawp a ngai thin a, chutih hunah chuan kan condition siam chhungah chuan dah chhawn zel theih a ni. Hetiangin:

<?php
if($state == 'Mizoram')
{
     if($district == 'Champhai')
     {
          if($capital == 'Champhai')
          {
              $result = 'dik';
          }
     }
}
?>

Hetiang Nested ngai duat ang chi-ah hi chuan, Logical Operator hmangin line tlem zawkin siam mai theih a ni. Hetiangin:

<?php
if($state == 'Mizoram' && $district == 'Champhai' && $capital == 'Champhai')
{
     $result = 'Dik';
}
?>


CONDITIONAL STATEMENT, FORMS LEH RESULT PAGE DAHKAWP DAN
PHP hmanga form siam tam takah chuan, a hranpain html page-ah form siamin action-ah PHP script file hran dah a ni thin a. Amaherawhchu HTML Form leh PHP script zawng zawngte hmunkhatah kan dahkhawm vek dawn a ni.
A hnuaiah hian form pakhat kan hmu a, PHP special container $_POST hmangin form submit leh submit loh  kan check pah nghal dawn a. Form chu submit a la nih loh chuan HTML form lo langin, submit tawh a nih erawh chuan script hmanga hnathawkin result page a rawn lang mai dawn a ni.

<html>
<head>
<title>CHHURA</title>
</head>
<body>
<?php
//Tunah form chu la submit loh a nih chuan a hnuaia form hi a lo lang mai dawn a ni
if(!isset($_POST['submit']))
{
?>
<form method="POST" action="form.php">
Number Pakhat type la: <input type="text" name="nambar" size="20"><input type="submit" value="Send" name="submit"></p>
</form>
<?php
}
else
{
//Form chu submit a nih chuan a hnuaia mi hi a execute thung anga
//form atanga thil rawn thawn chu a hnuaia mi ang hian variable hmangin kan
//lo dah tha ang
$nambar = $_POST['nambar'];

     if($nambar > 0)
     {
          echo '+ve Number';
     }
     elseif($nambar < 0)
     {
          echo '-ve number';
     }
     else
     {
          echo 'Zero';
     }
}
?>

</body>
</html>

A chunga kan thil siam hi kan run a nih chuan thil pahnih kan hmu thei a. A hmasain page kan hawn ve leh thil chhutluhna tur text field a lo lang a. Button kan click hnuah result page a lo lang leh bawk ang. Submit button kan click veleh khan $_POST[‘submit’] key chu a zawng nghal a. A tul ang ang te a tih zawhah result a rawn tarlang ta thin a ni.

LOOPS
Loops chu statement in ang tihnawn nan hman a ni a. A code-a kha ziak nawn kher lovin, code tawite result kimchang tak si kan neih theih phah a ni.

while() loop
PHP loop zinga awlsam leh hmasa ber chu while() loop tiin kan sawi thei ang. Condition kan siam chu a dik chhung chuan while() loop chuan a hna a thawk char char mai dawn a, a dik loh ve leh a hnathawh a chawl chauh dawn a ni. Hetiangin:

<?php
while(condition a dik chhung)
{
     hei hi a thawk ang;
}
?>

Example: Kan naupan laia ‘Hmun’ kan zir thin ang kha loop hmangin kan la chhuak ang.
<?php
//Tunah kan hmun ziahlan tur leh a tawp hun tur kan siam anga
$hmun = 16;
$hmuntanna = 1;
$hmuntawpna = 15;
// Tunah loop siamin hmun formula kan ziak nghal bawk ang.
while($hmuntanna <= $hmuntawpna)
{
     echo "$hmun x $hmuntanna = " . ($hmun * $hmuntanna) . '<br>';
     $hmuntanna++;
}
?>
A chung while() loop-a kan hmuh chu $hmuntanna 1 atanga chhiar tanin  $hmuntawpna nen a intluk hunah kan loop siam chu a tawp chauh a ni.

do-while() loop
PHP-a do-while() loop-ah chuan loop chhunga statement awm kha vawikhat tal a execute hnuah condition a check chauh thin a ni. Hetiangin:

<?php
     do()
     {
          hei hi a ti hmasa ang;
     }while(hei hi a dik chhung chu);
?>

Entirnan: Hmun bawk kha lo en leh ta ila.
<?php
//Tunah kan hmun ziahlan tur leh a tawp hun tur kan siam anga
$hmun = 16;
$hmuntanna = 1;
$hmuntawpna = 15;
// Tunah loop siamin hmun formula kan ziak nghal bawk ang.
do
{
     echo "$hmun x $hmuntanna = " . ($hmun * $hmuntanna) . '<br>';
     $hmuntanna++;
} while($hmuntanna <= $hmuntawpna);
?>

for() loop
Statement thenkhat a zat bituk a hnathawhtir duh kan neihin for() loop hi hman a ni thin. Hetiangin:

<?php
for(initialize counter; conditional test; update counter)
{
     hei hi a ti ang;
}
?>

for() loop ah chuan execution siam hmain condition a test hmasa a, duh ang a nih chuan loop chu a execute leh a tichuan counter value chu pakhat(1) in a pung ta zel thin a ni. Condition test chu a dik loh hun hunah loop chu a tawp mai dawn a ni.
Entirnan:

<?php
for($m = 3; $m <= 100; $m++)
{
     echo "$m ";
}
?>

A chungah hian counter $m chu pathumin bul kan tan a, tichuan loop chuan conditional test-a kan hman 100 a thlen thlengin a hna a thawk mai dawn a ni.



ARRAYS LEH FUNCTION SIAMCHAWPTE
Variable i siam tam berah chuan value pakhat chauh a nei thin a, amaherawchu chu chauh chu a tawk si lo. Variable pakhat value engemawzat neia siam te i duh ta a. Chumi hunah chuan Arrays hi a tangkai ta chiah a ni.

<?php
//Array tunah kan siam ang
$infiamna = array('football', 'volley ball', 'tennis', 'hockey', 'badminton');
?>

A chungah hian $infiamna hi array variable a ni a. chu chuan football, volleyball, tennis, hockey leh badminton te a keng tel nghal vek a ni.

Array variable-in value hrang hrang a neih te hi index number hmangin en leh mai theih a ni a. Value hmasa ber chu zero atangin a in tan a, chuti a nih chuan $infiamna[2] chu tennis a ni. Heta thil lo lang ta chu, array variable square bracket chhunga index number awm nena inzawm chu a ni. Tin, PHP ah hian keimahnin “keys” kan siam chawp thei bawk a. key kan siam reng reng chuan array chhunga value kan pek ang zelin a bik taka hlutna nei an ni ta zel a ni. Hetiang hian key chu kan siam thei a.

<?php
//Associative Array kan siam hmasa anga
$thilmak = array('tahbelh' => 'hnapngah', 'bengcheng' => 'rsi', 'hmeltha' => 'diktei', 'chawheh' => 'tei');
?>

A chungah hian $thilmak hi Array variable a ni a chu chuan key pair pali a keng tel a. => hi key leh a value zawmkhawm nan hman a ni a. rsi en tur chuan $thilmak[‘bengcheng’] kan hman a ngai a, chutiang zelin a dang pawh. Hetiang ang chi array hi a chang chuan hash emaw associative array tih a ni thin.

Array siamdan
Array() hmangin array variable a hnuai a mi ang hian kan siam thei a.

<?php
//Array tunah kan siam ang
$infiamna = array('football', 'volley ball', 'tennis', 'hockey', 'badminton');
?>

Tin, index hmangin array kan siam thei bawk.

$infiamna[0] = ‘football’;
$infiamna[1] = ‘volleyball’;
$infiamna[2] = ‘tennis’;
$infiamna[3] = ‘hokkey’;
$infiamna[4] = ‘badminton’;

Tin, Associative array siam tur chuan index atana number hman aiah keys hman tur a ni.
<?php
//Associative array kan siam anga
$thilmak['tahbelh'] = 'hnapngah';
$thilmak['bengchheng'] = 'rsi';
$thilmak['hmeltha'] = 'diktei';
$thilmak['chawheh'] = 'tei';
?>

Array-a thilawmte (elements) tihdanglam dan
Array-a thil belh tur chuan index number emaw key emaw hmangin belh mai tur a ni. Hetiangin:

<?php
//index number hmanga array siamah tiang hian kan belh anga
$infiamna[5] = 'invaivawm';

//index number belh tura tak kha i hre lo palh hlauh a nih pawhin
//A hnuaia mi ang hian a dik thei tho
$infiamna[] = 'invaivawm';

//Tunah associative array-ah thil kan lo belh anga
$thilmak['fel'] = 'bektei';
?>

Tin, value nei sa array chu kan tidanglam duh a nih chuan a ding lama value kha thlak mai tur a ni. A chung atanga kan hmuh chu $infiamna[5] = ‘invaivawm’; tih a ni. $infiamna[5] value hi kan thlak duh chuan a dinglama value hi thlak mai tur a ni. Hetiangin:
$infiamna[5] = ‘silai kah’;
Tin, array_pop() emaw, array_push() hmangin array-a thilawmte kan paih thei bawk.
Loop leh Arrays hnathawhkawp dan
A hnuaia loop entirna atang hian lo en ila:

<html>
<head>
</head>
<body>
Vawiina Seminar Thupui turte:
<ul>
<?php
//Array tunah kan siam ang
$mizothawnthu = array('mauruangi', 'raldawna leh tumchhingi', 'zawlpala leh tualvungi', 'Lalruanga');

//Tunah for() loop siamin array-a thute chu kan dahchhuak ang
for($x = 0; $x < sizeof($mizothawnthu); $x++)
{
     echo "<li>$mizothawnthu[$x]";
}
?>
</ul>
</body>
</html>

A chungah hian for() loop hi array kan siam lakchhuah nan kan hmang a, thil thar pakhat kan hmuh belh chu sizeof() hi a ni, he sizeof() array function hi kan array siam-a thil(elements) awm zat lak chhuah nan kan hmang a ni.

foreach() loop
He loop-ah hi chuan array element tin kha chawp leh chilh a enfiah nghalin, element pakhat a tih zawhah a dawttuah a kal leh a, tin for() loop ang a, counter ngai lovin, sizeof() pawh a ngai chuang lo a ni. Hriatthiam zual nan a hnuaia entirna hi lo en ila:

<html>
<head>
</head>
<body>
Vawiina Seminar Thupui turte:
<ul>
<?php
//Array tunah kan siam ang
$mizothawnthu = array('mauruangi', 'raldawna leh tumchhingi', 'zawlpala leh tualvungi', 'Lalruanga');

//Tunah for() loop siamin array-a thute chu kan dahchhuak ang
foreach($mizothawnthu as $item)
{
     echo "<li>$item";
}
?>
</ul>
</body>
</html>

foreach() loop nen hian Associative Array pawh i hmang thei a. A hnuaia entirna hi en la:

<html>
<head>
</head>
<body>
Vawiina Seminar Thupui turte:
<ul>
<?php
//Associative Array tunah kan siam ang
$mizothawnthu = array('mauruangi' => 'vailal nupui', 'raldawna leh tumchhingi' => 'Hmeltha pahnih', 'zawlpala leh tualvungi' => 'Innei thei lo', 'Lalruanga' => 'Dawithiam');

//Tunah for() loop siamin array-a thute chu kan dahchhuak ang
foreach($mizothawnthu as $key => $value)
{
     echo "<li>$value chu $key a ni";
}
?>
</ul>
</body>
</html>

Arrays hmanga form selection siam dan
Loops leh arrays pangai bakah PHP form kan siam a nih chuan checkboxes leh multiselect ang chi-ah te array hmangin variable pakhatah value tam tak chu a hnua hman leh awlsam nan dah theih a ni. A hnuaia script hi en la:

<html>
<head>
</head>
<body>

<?php
//Form chu submit a nih leh nih loh tunah kan en anga
if(!$_POST['submit'])
{
     //submit a nih loh chuan a hnuaia form hi a lo lang ang
?>
     A hnuaia mi hi i duh select la:<br />
     <form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
     <select name="duhthlan[]" multiple>
     <option value="Rebeki">Rebeki</option>
     <option value="Lucy">Lucy</option>
     <option value="Remsiami">Remsiami</option>
     <option value="Rinawma">Rinawma</option>
     <option value="Tei">Tei</option>
     <option value="Joseph">Joseph</option>
     </select>
     <input type="submit" name="submit" value="select">
     </form>
<?php
}
else
{
     //Form chu submit a nih chuan
     //Engemaw tal select a ni em tih kan en anga
     //Select a nih chuan kan select ho chu kan tilang ang
    
     if(is_array($_POST['duhthlan']))
     {
          echo 'A hnuaia mi hi i thlante chu a ni: <br />';
          //array a thute tilang turin foreach() loop
//kan hmang ang a
          foreach($_POST['duhthlan'] as $hmingsangi)
          {
              echo "<i>$hmingsangi</i><br />";
          }
     }
     else
     {
          echo 'Engmah i select lo';
     }
}
?>
</body>
</html>

A chunga kan hmuh pawimawh tak chu <select> in a ken tel PHP array siam nana kan hman bracket hi a ni. Form chu submit a nih ve leh PHP chuan chawp leh chilhin kan thil select te lo dahthat nan array variable a siam nghal a. Chu array chu foreach() loop hmangin kan la chhuak leh ta a ni.

Array functions hmanna
Associative arrays I hmang a nih chuan, array_keys() leh array_values() function-te array chhunga key leh value lakchhuah nan hman theih a ni. A hnuaia entirna hi en la:

<?php
//Associative array kan siam anga
$mizothawnthu = array('mauruangi' => 'vailal nupui', 'raldawna leh tumchhingi' => 'Hmeltha pahnih', 'zawlpala leh tualvungi' => 'Innei thei lo', 'Lalruanga' => 'Dawithiam');

//key arrays ho chauh array('mauruangi', 'raldawna leh tumchhingi', 'zawlpala leh tualvungi', 'lalruanga')
//kan la chhuak ang
$result = array_keys($mizothawnthu);

//Tunh array values ho zawng kan la chhuak leh ang
$result = array_values($mizothawnthu);
?>

Variable chu array a nih leh nih loh endik turin is_array() function a hnuaia entirna ang hian kan hmang ang a.

<?php
//Array tunah kan siam ang
$chawhmeh = array('zikhlum', 'alu');

//array a ni tih tichiang turin 1 (true) a rawn tilang ang
echo is_array($chawhmeh);
?>

list() leh extract() function hmangin array element-te chu PHP variable pangaiah siam theih a ni. list() function hian array element-te chu variable-ah a siam mai a ni.

<?php
//Array tunah kan siam ang
$chawhmeh = array('zikhlum', 'alu', 'antam', 'behlawi');

//values ho chu variables-ah kan siam ang a
list($chaw1, $chaw2, $chaw3, $chaw4) = $chawhmeh;
//A hnuaia mi hian 'antam' a rawn tilang ang
echo $chaw3;
?>
extract function chuan key-value inkawp kha variable-value inkawp-ah a siam a. A hnuaia entirna hi en la.

<?php
//Associative array kan siam anga
$mizothawnthu = array('mauruangi' => 'vailal nupui', 'raldawna leh tumchhingi' => 'Hmeltha pahnih', 'zawlpala leh tualvungi' => 'Innei thei lo', 'Lalruanga' => 'Dawithiam');

//values ho chu variable-ah a siam a
extract ($mizothawnthu);

//A hnuaia mi hian "Dawithiam" a rawn tilang ang
echo $Lalruanga;
?>

Array awmsa tawpah thil (element) I belh duh chuan array_push() function hman tur a ni a. Tin, Array tawp atanga thil awmsa paih duh chuan array_pop() function hman leh mai tur a ni. Tin, array hmasa ber atanga thil I paih duh chuan array_shift() function I hmang thei a, tin array_unshift() function hi array awmsa hma lam bera thil belh nan hman a ni bawk. A hnuaia entirna hi en la:


<?php
//Tunah Array kan siam anga
$naupang = array('siama', 'kunga', 'lala');

//array-a thil awm hmasa ber 'siama' tih hi
//array kan siam atang hian kan paih ang
array_shift($naupang);

//Array-a a tawp ber 'lala' tih hi kan paih ang
array_pop($naupang);

//Tunah 'Lawma' tih hi array awmsa tawpah kan belh ang
array_push($naupang, 'Lawma');

//Liana tih hi array tirah kan belh leh ang
array_unshift($naupang, 'Liana');

//Tuna array lan dan tur chu ('Liana', 'kunga', 'Lawma')
print_r($naupang);
?>

explode() function hmang hian string ang chi te a phel nawi theih a. A hmangtu duhdan a zirin coma emaw, space emaw, tab khat emaw kan duh dan angin kan phel thei a ni. A hnuaia entirna hi en la:

<?php
//string tunah kan siam anga
$tawnghrang = 'Mizo English Hindi Kawl';

//space khat zel hmangin kan la hrang ang
$tawng = explode(' ', $tawnghrang);

//$tawng in a ken tel tawh tur chu
//('Mizo', 'English', 'Hindi', 'Kawl')
?>

Hemi letling chiah hian implode() function hmangin thil hrang hrang kan dah khawm thei bawk. Hetiangin

<?php
//string tunah kan siam anga
$tawnghrang = 'Mizo English Hindi Kawl';

//space khat zel hmangin kan la hrang ang
$tawng = explode(' ', $tawnghrang);

//$tawng in a ken tel tawh tur chu
//('Mizo', 'English', 'Hindi', 'Kawl')

//Tunah string thar kan siam ang
$tawngthar = implode(" leh ", $tawng);

//A chunga implode() function-in a rawn tih chhuah tur chu
//(Mizo leh English leh Hindi leh Kawl) a ni.
?>

function siam chawp
Function kan tih chuan program statement dahkhawm engemaw bik thawk tura siam tiin kan sawi thei ang a. Chu program dahkhawma chu I program ziah lai khawi hmun atang pawhin I hmang mai thei tawh a ni. Function siam dawn in a bik taka siam hming function tih chu function hmingin a zui nghal thin. A hnuaia entirna hi en la.

<?php
function mizo()
{
echo 'Mizoram hi kan ram a ni, hei lo chu ram dang kan nei lo';
}
//kan function siam chu kan hmang ang
mizo();
?>

Function Arguments
I function siamah chuan Arguments I belh thei a, hetiangin:

<?php
//tunah function argument pakhat chauh nei kan siam anga
function milestokm($miles)
{
     echo "$miles miles = " . $miles * 1.60 . " km";
}

//tunah kan function siam chu kan la chhuak anga
//argument pakhat kan dah ang
milestokm(20);
?>

Tin, return statement kan hmangin return value kan siam thei a. A hnuaia function pakhat argument pahnih nei hi en leh la

<?php
//Tunah function kan siam anga
function trianglearea($base, $height)
{
     $area = $base * $height * 0.5;
     return $area;
}

//Tunah kan function siam chu kan la chhuak ang
echo 'The area of triangle is ' . trianglearea(30, 40);
?>

A chungah hian trianglearea() function hi kan lak chhuah duh ve leh, area formula kan siam chu chawkin $area variable-ah a dikna chu a dah a. Tichuan return statement hmangin a dikna chu main program-ah a rawn dah chhuak mai a ni. Thil hriattur pakhat chu PHP program-ah return statement a lo awm chuan chu function-a a hna thawh chu tawpin a tihchin zawng result chu a pe chhuak nghal mai thin a ni.

Local leh Global variables
Function pakhat chhunga variable I hman chu chu function chhungah chauh chuan a hman theih a, amaherawhchu main program-ah variable chu I lo siam tawh a nih si chuan, main program chhunga function-ah chuan variable ngai bawk I siam leh a nih chuan thil dik lo te a awm theih phaha, chuvangin global keyword hmangin he harsatna hi kan su kiang thei a ni.

<?php
//Tunah variable pahnih kan siam anga
$itemCount = 65;
$employeeCount = 125;

//Function tunah kan siam anga
function addItems()
{
     global $itemCount;
     $itemCount = $itemCount + 100;
}

//Tunah function pakhat local variable
//global variable (mahse global keyword hman lohna)
//nena in ang chiah kan siam anga
function addEmployees()
{
     $employeeCount = 2000;
}

//A hnuaia mi hian 65 a pe ang
echo "A tira Items zat chu: $itemCount";
addItems();

//Hei hian 165 a pe ang
echo "AddItems() hnua item zat chu: $itemCount";

//125 a pe ang
echo "A tira employee zat chu: $employeeCount";
addEmployees();

// 125 a pe ang
echo "addEmployees() hnua employee zat chu: $employeeCount";
?>

function kan siamte hi file dangah save-in chu file chu include() emaw require() function hmangin kan la chhuak leh thei. Hetiangin
<?php
//kan function file kan la lut ang
include("/path/function.php");

//Hetah hian function chu la chhuak la
?>
A chungah hian include() function kan hmu a, hei hian include file-a kha a hmuh loh chuan warning error a rawn pe ang a, mahse a script chhiara chu a tawp chuang lo ang. Tin, include aiah hian require() function kan hmang a nih chuan file mamawh chu a hmuh loh chuan error a rawn siam bakah file a awm loh thu warning error a rawn pe-in script hnathawh chu chhun zawm loin a tawp nghal hmak mai ang.

FILES, SESSIONS, COOKIES
PHP-a thil pawimawh tak tak- variables, operators, conditional statements, loops, arrays leh file include dan thlengin kan zir tawh a. Chuvangin thuk leh zual zawkin PHP tunah kan luh chilh dawn a ni.

Files-a thu awm lak dan leh Files siam dan
PHP hi File API(Application Programming Interface) chak tak leh tihdanglam awl tak mai nei a ni a. chu chuan developer te tan file attributes, tih dang lam leh en bakah, directory chhunga file awm te lak chhuah leh, file permission hrang hrang tihdanglam te, file chhunga thil awm en theihna bakah, engemaw bik hmanga files zawn dan thlengin a ti awlsam em em a ni.

File chhunga thilawm chhiar dan
A hmasain file hawn dan leh a chhunga thil awm chhiar dan kan en anga. Kan hriattur chu $file value kan siam hi a path dik tak I enchhin hunah dah theih nghilh lo la.

<?php
//Tunah kan file chhiar tur chu kan siam anga
$file = 'mizo/test.txt';

//File chu kan hawng ang
$fhawng = fopen($file, 'r') or die('File kan hawng thei lo tlat');

//Tunah file chhunga thil awm chu kan chhiar ang
$fchhiar = fread($fhawng, filesize($file)) or die ('File chhunga thil awm a chhiar theih loh');

//File chu kan hawn chu kan khar leh anga
fclose($fhawng);

//Tunah file chhunga thil awm chu chhiar theihin kan dahchhuak ang
echo $fchhiar;
?>

A chunga kan script siam atang hian a kal hmang tlem lo sawi leh ila.
(i) A hmasa berin file kan hawn tur a chu siamin variable pakhat $file chu kan siam nghal a. Chu variable kan siam chu hawng turin fopen() function hmangin variable pakhat $fhawng tih chu kan siam leh ta a. Hetah hian file chu engtia tihtur nge tichiang turin (‘r’) kan dah tel a ni.
(ii) fopen() function kan siam chu a hlawhtling a nih chuan a lo kengtu variable $fhawng chu a hnu lama fread() function hmanga en leh turin a rawn chhawp chhuak leh ta a, fread() function hmang chuan file chu enin a chhunga thil awm te chu variable pakhat $fchhiar ah kan chhawp chhuak leh a ni. Fread() function chhunga filesize() function kan hman hian kan file a chu a len zawng byte hmangin a rawn tar chhuak a ni.
(iii) fclose() function hmangin file I en tawh chu I khar leh ta a. fclose() function hman fo chin hi memory kan hman teuh loh nan chin fo a tha a ni. Hei hi tih ngei ngei tur a ni lo a. Mahse chin thanah erawh a tha.

Hemi ni lo file-a thil awm chhiarna atana hman awlsam tak mai pakhat chu file() function hi a ni a. Hei hian file pumpui a thil awm chu array hmangin a chhiar thei a ni. File-a thil awm chu chhiar turin foreach() loop hmangin file chhung line tina thil awm te chu kan lachhuak thei a ni. A hnuaia entirna hi en la.

<?php
//Tunah kan file chhiar tur chu kan siam anga
$file = 'mizo/test.txt';

//Tunah file chhunga thil awm chu kan chhiar ang
$fchhiar = file($file) or die ('File chhunga thil awm a chhiar theih loh');

//File chu array kal tlanga loop siamin line tinte chu kan la chhuak ang


foreach($fchhiar as $line)
{
     echo $line;
}
?>

Note: die() function hi error a awm a ni tih tihchianna atana hman lar tak chu a ni a. die() hmang hian script-a error awm chu tarlangin script hnathawh lai chu a chawl ta thin a ni. Fopen() function-ah hian mode chithum I hmang thei a. chu chu ‘r’ (file chhiar theih chauh a dahna) ‘w’ (hei hian file awmsa chu chhiar theih mai ni lovin, a awmsa thlakthleng theihin phalna a pe a. ‘a’ (hei hian file chu chhiar theiha a dah bakah a awmsa tichhe lo in dahbelh tur a awm chuan a dahbelh mai a ni.)

File chhunga thil awm lakchhuah dan chikhat dang leh chu file_get_contents() function hmangin a ni. Hei hi PHP 4.3.0 leh PHP 5.0 ah dah chauh a ni a. Chu chuan file chhunga thil awm zawng zawng kha string angin a chhiar ta thin a ni. A hnuaia entirna hi en la.

File-a thil dah luh dan
File-a thil dahluh dan leh, lakchhuah dan chu a kalhmang a in ang deuh vek a, a in an lohna chu ‘r’ aiah ‘w’ fopen() function-ah hian hman mai tur a ni a, tin fread() function aiah fwrite() function hman tur a ni bawk. A hnuaia script hi han en la.

<?php
//Tunah kan file siam tur chu kan ziak anga
$file = 'mizo/pawnga.txt';

//File chu kan hawng ang
$fhawng = fopen($file, 'w') or die('File ka siam thei lo tlat');

//Tunah file chhungah thil kan dah lut ang
fwrite($fhawng, 'Hei hi pawnga.txt ah chuan dahluh a ni.') or die ('File chhunga thil awm a chhiar theih loh');

//File chu kan hawn chu kan khar leh anga
fclose($fhawng);
?>

Hemi bakah hian file-a thil dahluh nan chuan file_put_contents() function kan hmang thei bawk. Hei hi PHP 5.0 a thil thar belh a ni a. Chu chuan kan thil dahluh tur-a kha string anga lain file-ah line khat angin a dahlut mai a ni. Hetiangin

File Attribute hrang hrang te enna
PHP chuan file dinhmun hrang hrang enna turin function engemawzat a keng tel nghal a, A hnuaiah hian function thenkhat chu dahlan a ni.

Function
An hnathawh
file_exists()
File chu a awm ngei leh ngei loh a enfiah
is_dir()
Kan path dah chu directory a ni ngei em tih a enfiah
is_file()
Kan file chu file pangai a ni ngei em tih a enfiah
is_link()
Kan file chu symbolic link ang chi a ni em tih a enfiah
is_executable()
File chu executable a ni em tih a enfiah
is_readable()
File chu en theih/ chhiar theih a ni em tih a enfiah
is_writable()
File chu tihdanglam theih a ni em tih a enfiah
filesize()
File len zawng bytes in a la chhuak
filemtime()
File tihdanglam hnuhnun ber hun a la chhuak
fileatime()
File en hnuhnun ber tum a la chhuak
fileowner()
File neitu/siamtu a lachhuak
filegroup()
File group a lachhuak
fileperms()
File chu enga tihdanglam theih nge tih a enfiah
filetype()
File chu eng data type nge tih a enfiah

A chunga Function hrang hrang kan neih atang hian a awmzia hre turin a hnuai a mi ang hian script lo siam tai la.

<?php
//kan file hming chu kan la anga
$file = $_GET['file'];

//File chu a awm ngei em tih kan enfiah ang
echo file_exists($file) ? 'File a awm e' : 'File a awm lo reng reng';

//File chu executable a ni em tih kan enfiah ang
echo is_executable($file) ? 'Executable a ni ngei e' : 'File chu executable a ni lo';

//File chu chhiar theih a ni em tih kan en ang
echo is_readable($file) ? 'Chhiar theih a ni' : 'Chhiar theih a ni lo';

//File chu tihdanglam theih a ni em kan en ang
echo is_writeable($file) ? 'Tihdanglam theih a ni e' : 'Tihdanglam theih a ni lo';

//Tunah file chu engtia lian nge tih kan en leh ang
echo '<br>File len zawng chu' . filesize($file) . 'Bytes';

//Tunah file neitu/Siamtu kan en ang (Linux/Unix OS tan bik deuh)
echo '<br>File siamtu neitu chu' . fileowner($file);

//File chu eng data type nge tih kan en leh ang a
echo '<br> Kan file data type chu:' . filetype($file);

//FIle tihdanglam hnuhnun ber hun kan en ang Unix timestamp angin
echo '<br> File tihdanglam hnuhnun ber chu:' . filemtime($file);
?>

Directory chhunga file awmte endan
File pakhat tete han tih vel dan kan zir tawh a, tunah chuan directory han khawih vel dan leh, directory chhunga file awm endan kan zir leh ang.


<?php
//Tunah counter kan siam ang
$counter = 0;

//Directory hming kan en leh anga
//He directory hi i siam ve ngei a ngai
$dir = "mizo";

//Tunah directory chu hawngin a chhunga file chu kan list out ang
if(is_dir($dir))
{
      if($dh = opendir($dir))
      {
            //File list kan siam ang
            //File chu kan list ang
            while(($filename = readdir($dh)) !== false)
            {
                  if(($filename != ".") && ($filename != ".."))
                  {
                        $count++;
                        echo '<br>File te chu:<br>' . $dir . "/" . $filename . "\n";
                  }
            }
      //Directory tunah kan close ang
      closedir($dh);
      }
}
echo "<br><br>$dir Directory chhungah files $count hmuh a ni.";
?>

A chungah hian opendir() function hmangin directory hming lo neitu tur variable kan siam a. readdir() function hmangin directory chhunga file awm ho te lo neitu tur variable pakhat $filename chu kan siam leh a. Chu chuan directory chhunga file awm te chu a mal te tein a chhiar a. Chumi hnuah directory neitu kan siamte chu closedir() hmangin kan titawp leh a ni.

Sessions leh Sessions variable tangkaina
Online shopping website tam tak kan hre thin a, keini pawhin kan tlawhin kan hmang fo a ni thei e. Hengah te hian tuna kan sawi tur hi a pawimawh tak zet mai. Website tlawhtute chet vel dan hrim hrim leh, website an en hun chhung te lo chhinchhiah leh, website tlawhtu atanga thil hrang hrang awm theite lo enfiah turin session hi a pawimawh hle a ni. Chutiang lo tih theihna chu PHP hian a nei a.
Kan hriattur pawimawh tak mai pakhat chu session data store nan session_start() hman thin a ni a. Heng session kan siam ang chi hi <html> hma lamah dah ngei ngei tur a ni. Hei hi a chhan chu HTTP protocols hian cookies leh headers dang reng reng te script dang output awm hma a inthawn vek tura a tih vang a ni.

A hnuaia script tawite atang hian session leh session variable hnathawh dan lo en tai la.
<?php
//Phek hmasa
//Tunah session kan siam ang
session_start();

//Session variable thenkhat kan register anga
$_SESSION['hming'] = 'pawnga';
$_SESSION['nihna'] = 'tlangau';
?>

A chunga session kan siam hi phek khatnaah kan siam tih hre reng ila, phek hnihnaah kan session siamsa chu kan en leh thei a. Hetiangin

<?php
//phek hnihna
//Session kan siam hmasak chu kan tinawn leh anga
session_start();
//Session phek hmasaa kan siam sa chu kan en ang
//Tah hian ‘pawnga’ tih a rawn lang ang
echo $_SESSION['hming'];
?>

Session siamsa thiat/paih leh dan
Website hmangtu logout ang chi ah te session kan siamsa chu paih leh a ngai thin a. Chutih hunah chuan $_SESSION array chu reset in, session_destroy() function hmangin session siamsa chu thiat leh mai tur a ni. A hnuai entirna hi en la.

<?php
//Session chu kan siam tha leh anga
session_start();

//Tunah session array chu kan reset ang
$_SESSION = array();

//Session tunah kan thiat ang
session_destroy();
?>

Note: session_destroy() function hmanga session i thiat hmain session chu session_start() hmangin i siam hmasak leh phawt zel a ngai tih i chhinchhiah tlat dawn nia.

Cookies-a thil dahthat dan
Cookie chuan website hmangtu information hrang hrangte file-ah a lo dahtha a, a hnuah a tul dan a zirin a la chhuak leh thin. Cookie hi website tlawhtu browser hmanah a in nghat bawk.
Cookie hman theihna hi PHP 3.0 atangin a theih tan a. PHP function neihsa hmangin website tlawhtu cookie chu i siam thei a, Tin, cookie in thil a kente chu dahthain, i duh chuan engemaw chen hnua in paih leh mai turin i siam thei a ni.
Cookie i siam dawnin a hnuaia mi te hi chhin chhiah la.

(i)     Cookie-te chu i site tlawh pakhata i chet dan hrang hrangte dahthatna a ni a. Chuvangin chu i site tlawh pakhatah chauh chuan i site tlawh laia cookie insiam chu hman leh theih a ni.
(ii)    Domain pakhatin cookie 20 aia tam a siam thei lo a. Tin, cookie pakhat chuan 4KB zela lian a keng thei bawk.
(iii)  Cookie chuan attributes 5 a nei a. Chungte chu:

Attributes
An hnathawh
Name
cookie hming leh value a siam a
Expires
Cookie tawp hun tur ni leh hun a siam
path
domain-ah cookie data te kan enna tur directory a siam a
domain
cookie kan siam hmantheihna chin tur domain a siam a
secure
HTTP secure connection-ah hauh cookie in siam thei turin a buatsaih.

(iv)    Heng a chunga attribute hrang hrangah hian a hmasa ber tihloh chu optional vek a ni.
Cookie siam dan
PHP-ah chuan setcookie() function hmangin cookie chu siam a ni a. Chu chuan argument hrang hrang paruk a nei thei a: cookie hming, a value, a tawp hun(UNIX TIMESTAMP hmangin), path leh domain, leh security status. A hmasa ber cookie hming chiah hi ngei ngei tur a ni a. A dang chu telh duh leh duh loh a ni mai.

<?php
//Tunah cookie pakhat ‘hming’ a value ‘pawnga’ tih kan siam anga
//Nikhat hnua chu cookie chu tawp turin kan siam ang
setcookie('hming', 'pawnga', mktime()+86400, '/');
?>

setcookie() function hmanga thil kan siam chu a dik a nih chuan leh cookie kan siam chu browser-ah a inthawn ngei a nih chuan a dik tih message rawn siamturin kan siam thei a ni.

<?php
//Tunah cookie pakhat hming a value pawnga tih kan siam anga
//Nikhat hnua chu cookie chu tawp turin kan siam ang
$result = setcookie('ming', 'pawnga', mktime()+86400, '/');

//Cookie chu a siam leh siam loh i check anga
//A insiam lo a nih chuan a hnuaia error message hi a rawn pe ang
if(!$result)
{
      echo "Cookie a siam theih loh";
}
//Cookie chu a insiam a nih chuan
else
{
      echo 'cookie a in siam e' . $result;
}
?>

setcookie() function hmang hian a rualin cookie pakhat aia tam kan siam thei a. A hnuaia entirna hi en la.

<?php
setcookie('hming', 'pawnga', mktime()+86400, '/');
setcookie('hna', 'OMM',mktime()+1800, 'mizo/domain/');
setcookie('veng','MSVT', 0, '/');
?>

Note: mktime() function hian date leh time insiam chu Unix timestamp-ah a let a ni.

Cookie-a thil dahsa lakchhuah dan
Domain atana cookie siam a nih tawh chuan $_COOKIE associative array hmangin lakchhuah theih a ni a. A hnuaia entirna hi en la.

<?php
//Cookie siamsa a awm chuan a hnuai a mi ang hian a tilang ang
if($_COOKIE['hming'])
{
      echo "Welcome back:" . $_COOKIE['hming'];
}
//Cookie insiam sa a awm loh chuan
//A hnuaia mi hi a lang thung ang
else
{
      echo "I vawikhat hawnna a ni";
}
?>

Note: i cookie siam chu a dik ngei em tih en turin hetiang hian script siamin i browser atang khan han PHP special $_COOKIE array chu en teh le
<?php print_r($_COOKIE); ?>

Cookie paih dan
Cookie paih tur chuan setcookie() function hmangin a hmaa cookie i siam tawh sa tawp hun tur i siam kha mktime()-ah khan paih mai tur a ni. Hetiangin:

<?php
setcookie('hming', NULL, mktime()-86400);
?>

Dates leh Times
Date leh time siama han tarlan vel hi web application siam chuan tihmakmawh ang deuh a ni thin a. PHP hian chutianga Date leh time han suasam velna tur chu a rawn keng tel a ni.

Tuna hun kal lai mek lakchhuah dan
getdate() function hmangin tuna hun kal lai mek ni leh darker zawng zawng lakchhuah mai theih a ni a, chu kan thil lakchhuah chu array hmangin kan tarchhuak leh mai dawn a ni.

<?php
//Tuna hun kal lai mek kan la chhuak ang
$tun = getdate();

//Kan thil lakchhuah chu string-ah kan chantir ang
$tun_hun = $tun['hours'] . ':' . $tun['minutes'] . ':' . $tun['seconds'];
$tun_ni = $tun['mday'] . '.' . $tun['mon'] . '.' . $tun['year'];

// Tunah kan string siamsa chu kan tarchhuak ang
echo "Vawiin hi $tun_ni, dar $tun_hun a ni";
?>

Heta kan hmuh chu getdate() function chuan associative array keys te hour, minute, second, day, date, month, year a keng a. Chu chu array pangai hmangin kan va lachhuak thei ta a ni.

Dates leh Times atana Timestamps hnathawh
PHP date function reng reng hi timestamp-a innghata hnathawk vek a ni a. He timestamp hi number aiawhtu bik hmangin lakchhuah a ni thin. PHP ah chuan timestamp te chu mktime() function hmangin siam a ni. Chu chuan date leh time te chu la in timestamp-ah a lo let thin a ni. A hnuai entirna hi en la.

<?php
//22:06:00 July 29 2007 hi timestamp hmangin kan dah anga
echo mktime(22,06,00,6,29,2007);
?>


Hun ruat bik atana timestamp i la duh a nih chuan mktime() function-ah heng argument hrang hrang- hour, minute, second, month, day, leh year te dah la. Tin, tun hun atana timestamp i la duh a nih chuan argument tel lovin, mktime() function chauh hi hmang mai ang che.

Popular posts from this blog

Eng-Mizo Dictionary leh Mizo-Eng Dictionary Hmandan kimchang.

Eng-Mizo Dictionary leh Mizo-Eng Dictionary hmandan hi hrelo tam tak kan awm niin a lang a, He Dictionary ah hian Word load lo chuan thu tam tak a hmu lo thin a, He Application hi i install veleh hawrawp 'a' hi Eng-Mizo Dictionary-ah hian 1547 search chhuah a ngai a, word load a tang a nih chuan Setting>> Applications >> Manage Application >> Downloads ah dictionary kha data clear a. Word load leh tur a ni. Word load dan: 

RAM lian 1GB RAM chin chunglam tan Vawikhat 'a' word i search a ang, 5minutes i ngak anga. Application close loh tur. 5minutes hnu ah 'a' word tho i search leh ang a. I chawl leh hlek anga. Word a hnuaia mi ang khuan i search chhuak dawn nia. ===================== Eng-Mizo Dictionary 'a' 1547 word
 Mizo-Eng Dictionary V1.4 update 'a' 709 word
https://www.dropbox.com/s/0lehiuxyrcit2e8/Mizo-Eng%20Dictionary.apk?dl=0=====================

I vawikhat search-naah khan search result-ah a chunglamah Number a rawn lang zel a, …

SIM CARD HRANG HRANG AIRTEL,RELIANCE,AIRCEL,BSNL,VODAFONE,IDEA THIL TRANGKAI:

1.AIRTEL:

Main Bal/Int pack/sms pck -*121*2#,
 INT settings - sms 'FUN' or 'MO' to 543210,
 UNSUB(VAS) - 'STOP' 121COMPANY call - START 0 to 1909
SIM no.enna - *282#, BAL Transfer na - Dial*141*1#,
 LOAN pukna - *141*10#,
 BAL atanga internet pck activate na -*567# ,
 Sms pck act na -*444#PUK - sms PUK(Space)i no. To 9862341400,
 Msg centre No. - 919862029007 Internet Setting dilna: MO send to 54321

2.RELIANCE :
Main BAL - *306#
Sms pck/min Bal - *367*2#
INT pck - Sms 'MBAL' to 55333
 INT settings - Sms 'ALL' to 55100
UNSUB(VAS) - 'STOP' to 155223
COMPANY Call - START 0 to 1909
SIM NO.enna - *1#
BAL Transfer na - Dial *367*3#
LOAN pukna - Sms 'YCR' to 51234MSG centre no. - 919863002222 Internet Setting dilna: Aircel type ALL or PI send to 121
3.AIRCEL :
Main BAL - *125# OR *128#INT pack - *129#
INT settings - sms 'PI' or 'ALL' to 121
UNSUB (VAS) - 'STOP' to 15522
3COMPANY call - call 1909
SIM no enna - *234*4#  or *131#or *1#
BAL t…

SETTOP BOX (Willett company) REMOTE SYNC DAN:

Settop box nei tawh ten Remote pahnin pathum hum reng kan peih lo tlangpui ang. Settop box a Volume phei chu 32 thleng a awm a, thenkhat tan chuan a ring tawk lo thei. tin, TV power off dawn a remote pahnih chhawp ziah pawh a ninawm thuai ang. A hnuaia mi ang hian ilo set ve mai dawn a nia. 1. Settop remote leh TV remote kha in sichat in; sensor veve in hawitawn tir la. 2. Settop remote ah khan SET tih (TV control tih chhung a mi) kha hmet vang vang rawh. Light a rawn sen phet ang. 3. Settop Remote a TV control tih chhung a V+ kha hmet lang. 4. TV Remote a volume + hmet leh rawh. a phe kha a muang atanga a phet zeuh zeuh hunah SET tih kha i hmet leh ang. Settop Remote a TV control a V+ kha TV zawnah hmet lang. TV volume a lo ring tawh ang. chu tiang chiah chuan V- te TV-IN (AV1-3) te, TV Power te kha set leh mai tur a ni.