Vous êtes sur la page 1sur 7

Ans-1 (a)

Usage of fles: Program varabes ose ther vaues after program executon. If we
want to retan data beng used n the program after the program executon then t
shoud be stored on externa storage devces n form of es.
Diferent Modes to open a fle
Modes Description
R Read ony. Starts at the begnnng of the e
r+ Read/Wrte. Starts at the begnnng of the e
W Wrte ony. Opens and cears the contents of e or creates a new
e f t doesn't exst
w+ Read/Wrte. Opens and cears the contents of e or creates a new
e f t doesn't exst
A Append. Opens and wrtes to the end of the e or creates a new
e f t doesn't exst
a+ Read/Append. Preserves e content by wrtng to the end of the e
X Wrte ony. Creates a new e. Returns FALSE and an error f e
aready exsts
x+ Read/Wrte. Creates a new e. Returns FALSE and an error f e
aready exsts
Ans 1(b)
Script:
<htm>
<body>
<?php
$ctes=array("|apan"=>"Tokyo","Mexco"=>"Mexco Cty","USA"=>"New York
Cty","nda"=>"Bombay","Inda"=>"Deh","Chna"=>"Shangha","Pakstan"=>"Lahore","UK
"=>"London");
//If form not submtted, dspay form.
If (! sset ($_POST |'submt'|))
{
?>
<form method="post" acton="youre.php">
<p>Pease choose a cty :</p>
<seect name="cty">
<?php
//Use array to create optons for seect ed.
foreach ($ctes as $c){
echo "<opton vaue=\"$c\">$c</opton>\n";
}
?>
</seect> <p />
<nput type="submt" name="submt" vaue="Go">
</form>
<?php
//If form submtted, process nput.
}ese{
//Retreve user response.
$cty=$_POST |'cty'|;
//Fnd correspondng key n assocatve array.
$country=array_search ($cty, $ctes);
//Send the data back to the user.
echo "<p>$cty s n $country.</p>" ;
}
?>
</body>
</html>
Ans: 2(a)
Script
<?php
$a=fgets(STDIN);
$b=fgets(STDIN);
$len1=strlen($a);
$len=strlen($b);
for($!=";$!<$len1;$!=$!#1)
$arr1$%=$a$$!%;
for($!=";$!<$len;$!=$!#1)
$arr$%=$b$$!%;
pr!nt&r($arr1);
pr!nt&r($arr);
$arr'=array&(o)nt&*al)es($arr1);
$arr+=array&(o)nt&*al)es($arr);
pr!nt&r($arr');
pr!nt&r($arr+);
$f=";
forea(h($arr' as $-=>$*al)
.
!f(array&-ey&e/!sts($-0$arr+))
(ont!n)e;
else
.
e(ho 1Not a s)bset1;
$f=1;
brea-;
2
2
!f($f==")
e(ho 1s)bset1;
?>
Ans 2(b)
<?php
e(ho 13nter str!ng 11;
$a=fgets(STDIN);
f)n(t!on re*erse($a)
.
for($!="0$4=strlen($a)5;$!<$4;$!##0$455)
.
$temp=$a$$!%;
$a$$!%=$a$$4%;
$a$$4%=$temp;
2
e(ho $a;
2
re*erse($a);
?>
Ans: 2(b) (i)
The GT Method
!n this "#er$ strings (na%e&'al#e pairs) is sent in the U() of a GT
re"#est:
/test/demo_form.asp*na%e1+'al#e1,na%e-+'al#e-
So%e other notes on GT re"#ests:
GET requests can be cached
GET requests reman n the browser hstory
GET requests can be bookmarked
GET requests shoud never be used when deang wth senstve data
GET requests have ength restrctons
GET requests shoud be used ony to retreve data
The ./ST Method
!n this "#er$ strings (na%e&'al#e pairs) is sent in the 0TT. %essage
bod$ of a ./ST re"#est:
Message 1od$:
POST /test/demo_form.asp HTTP/1.1
Host: w3schoos.com
na%e1+'al#e1,na%e-+'al#e-
So%e other notes on ./ST re"#ests:
POST requests are never cached
POST requests do not reman n the browser hstory
POST requests cannot be bookmarked
POST requests have no restrctons on data ength
Ans 2(b)(ii)
Difference between include and require
The two functons are used to nsert the content of a e nto another PHP e
before t s executed by the server. They are dentca n every aspect, but
they perform error handng n dherent ways. The ncude() functon
generates a warnng (whch does not hat executon) whe the requre()
functon generates a fata error (whch stops executon mmedatey).
Ans 3(a)
<htm>
<body>
Pease enter the vaues of the ength and wdth of your rectange
<form acton="resut.php">
<nput type=text name=t1>
<nput type=text name=t2>
<nput type=submt vaue=cacuatearea>
</form>
</body>
</htm>
<?php
$=$_GET|"t1"|;
$b=$_GET|"t2"|;
echo "A rectange of ength $ and wdth $b has an area of ". $*$b;
?>
Ans 3(b)
A class is an expanded concept of a data structure: instead of holding only data, it can hold both
data and functions.
An object is an instantiation of a class. In terms of variables, a class would be the type, and an
object would be the variable.
Classes are generally declared using the keyword (lass, with the following format:
(lass (lass&name .
a((ess&spe(!f!er&16
member1;
a((ess&spe(!f!er&6
member;
777
2 ob4e(t&names;
here (lass&name is a valid identifier for the class, ob4e(t&names is an optional list of names
for objects of this class. !he body of the declaration can contain members, that can be either data
or function declarations, and optionally access specifiers.
Script
<?php
class Student
{
private $rlln!"#
private $na$e!%%#
private $branch!%%#
private $&ear!"#
public functin ''cnstruct($rlln($na$e($branch($&ear)
{
$this)*rlln!$rlln#
$this)*na$e!$na$e#
$this)*branch!$branch#
$this)*&ear!$&ear#
+
public functin displa&()
{
ech %,lln is %-$this)*rlln-% .a$e is %-$this)
*na$e-%/ranch is %-$this)*branch-% &ear is %-$this)*&ear#
+
+
$s0!new Student(0(%Sahil%(%1S2%(0)#
$s2!new Student(2(%,ahul%(%1S2%(2)#
$s3!new Student(3(%,a3esh%(%1S2%(3)#
$s0)*displa&()#
$s2)*displa&()#
$s3)*displa&()#
?*

Vous aimerez peut-être aussi