WT Slip Solutions 1
WT Slip Solutions 1
WT Slip Solutions 1
Write a function
to count the total number of vowels (a,e,i,o,u) from the string. Show the occurrences of
each vowel from the string. Check whether the given string is a palindrome or not, without
using built-in function. (Use radio buttons and the concept of function. Use ‘include’
construct or require stmt.)
Ans:
<html>
<body>
<h4>Opertions :</h4>
<input type = "radio" name = "op" value = "3"> Check String is Palindrom or Not <br><br>
</form>
</body>
</html>
Slip.php
<?php
function cnt_vowels($a,$l)
$v_cnt = 0;
if(( $a[$i] == 'a') || ($a[$i] == 'e') || ($a[$i] == 'i') || ($a[$i] == 'o') || ($a[$i] == 'u') || ($a[$i] == 'A') ||
($a[$i] == 'E') || ($a[$i] == 'I') || ($a[$i] == 'O') || ($a[$i] == 'U')) $v_cnt++;
}
return $v_cnt;
function occur_vowels($a,$l)
$av=$ev=$iv=$ov=$uv=$cnt=0;
for($i=0;$i<$l;$i++)
$av++;
$ev++;
$iv++;
$ov++;
$uv++;
else $cnt++;
$tot = $av+$ev+$iv+$ov+$uv;
return $tot;
}
$str = $_POST['str'];
$op = $_POST['op'];
$l = strlen($str);
switch($op)
$v_cnt = cnt_vowels($str,$l);
break;
$v_occ = occur_vowels($str,$l);
break;
$str1=strrev($str);
$a=strlen($str);
$f=0;
for($j=0;$j<$a;$j++)
if($str1[$j]==$str[$j])
$f=0;
else
$f=1;
break;
if($f==0)
echo"string is palindrome";
else
?>
step 3:localhost/seam3slip/slip1.html
Q.2Write a PHP script for the following: Design a form to accept two strings from the user. Find
the first occurrence and the last occurrence of the small string in the large string. Also count the
total number of occurrences of small string in the large string. Provide a text box to accept a string,
which will replace the small string in the large string. (Use built-in functions)
Ans:-
slip2.html
<html>
<body>
<center>
<table>
</table>
</center>
</form>
</body>
</html>
rslip.php
<?php
$str1 = $_GET['str1'];
$str2 = $_GET['str2'];
$str3 = $_GET['str3'];
$ch = $_GET['ch'];
If(strlen($str1)>strlen($str2))
switch($ch)
if($pos != 0)
break;
else
switch($ch)
if($pos != 0)
break;
break;
?>
Q.3:- Write a PHP script for the following: Design a form to accept two numbers from the user.
Give options to choose the arithmetic operation (use radio buttons). Display the result on the next
form. (Use the concept of function and default parameters. Use ‘include’ construct or require
stmt).
Ans:-
slip3.html
<html>
<body>
<table>
</table>
</form>
</body>
</html>
rslip.php
<?php
$no1 = $_GET['no1'];
$no2 = $_GET['no2'];
$cal =$_GET['cal'];
if($cal==1)
$add = $no1+$no2;
else if($cal == 2)
$sub = $no1-$no2;
else if($cal == 3)
$mult = $no1*$no2;
}
else if($cal == 4)
$div = $no1/$no2;
?>
Q.4 Write a PHP script for the following: Design a form to accept two strings from the user. Find
whether the small string appears at the start of the large string. Provide a text box to accept the
string that will replace all occurrences of small string present in the large string. Also split the large
string into separate words. (Use regular expressions)
Ans:-
slip4.html
<html>
<body>
<pre>
<input type='radio'
name="ch" value=3>split <input type=submit
value=ok>
</pre>
</form>
</body>
</html>
slip4.php
<?php
$str1=$_POST['str1'];
$str2=$_POST['str2'];
$str3=$_POST['str3'];
$ch=$_POST['ch'];
echo"First string=$str1.<br>";
echo"Second String=$str2.<br>";
if(strlen($str1)>strlen($str2))
switch($ch)
case 1: $pos=strpos($str1,$str2);
if($pos!=0)
else
break;
case 2:
$str4=str_replace($str2,$str3,$str1);
echo $str4;
break;
case 3: $s=preg_split("//",$str1);
foreach($s as $v) echo "\t$v <br>";
break;
else
switch($ch)
case 1:$pos=strpos($str2,$str1);
if($pos!=0)
else
break;
case 2: $str4=str_replace($str1,$str3,$str2);
break;
case 3:
$s=preg_split("//",$str2);
?>
Q.5 Write a PHP script for the following: Design a form to accept the details of 5 different items,
such as item code, item name, units sold, rate. Display the bill in the tabular format. Use only 4
text boxes. (Hint : Use of explode function.)
Ans:
slip5.html
<html>
<head>
<style>
table {
border-collapse: collapse;
table, th, td {
</style>
</head>
<body>
</center>
</form>
</body>
</html>
program5.php
<?php
$itemcode = $_POST['itemcode'];
$itemname = $_POST['itemname'];
$unitssold = $_POST['unitssold'];
$rate = $_POST['rate'];
$i_code = explode(',',$itemcode);
$i_name = explode(',',$itemname);
$i_unit = explode(',',$unitssold);
$i_rate = explode(',',$rate);
$t_amt =
(($i_unit[0]*$i_rate[0])+($i_unit[1]*$i_rate[1])+($i_unit[2]*$i_rate[2])+($i_unit[3]*$i_rate[3])+($i_u
nit[4]*$i_rate[4]));
echo
"<tr><td>".$i_code[0]."</td><td>".$i_name[0]."</td><td>".$i_unit[0]."</td><td>".$i_rate[0]."</td>
</tr>";
echo
"<tr><td>".$i_code[1]."</td><td>".$i_name[1]."</td><td>".$i_unit[1]."</td><td>".$i_rate[1]."</td>
</tr>";
echo
"<tr><td>".$i_code[2]."</td><td>".$i_name[2]."</td><td>".$i_unit[2]."</td><td>".$i_rate[2]."</td>
</tr>";
echo
"<tr><td>".$i_code[3]."</td><td>".$i_name[3]."</td><td>".$i_unit[3]."</td><td>".$i_rate[3]."</td>
</tr>";
echo
"<tr><td>".$i_code[4]."</td><td>".$i_name[4]."</td><td>".$i_unit[4]."</td><td>".$i_rate[4]."</td>
</tr>";
echo "</table>";
?>
Q.6 Write a PHP script for the following: Design a form to accept two strings. Compare the two
strings using both methods (= = operator &strcmp function). Append second string to the first
string. Accept the position from the user; from where the characters from the first string are
reversed. (Use radio buttons)
Ans:
slip6.html
<html>
<head><title> .html</title></head>
<pre>
</pre>
</form>
</body>
</html>
slip6.php
<?php
$str1=$_POST['str1'];
$str2=$_POST['str2'];
$pos=$_POST['pos'];
$ch=$_POST['ch'];
echo"choice is::$ch.<br><br>";
switch($ch)
case 1:
if($str1==$str2)
else
break;
case 2:
if($str1===$str2)
else
break;
case 3:
echo"After appending::";
echo "$str1"."$str2";
echo"<br>";
break;
case 4: $len=strlen($str1)-$pos;
$s=substr($str1,$pos,$len);
$str4=strrev($s);
break;
?>
Q.7 Write a menu driven PHP program to perform the following operations on an associative
array:
iv. Reverse the order of each element’s key-value pair.[Hint: use array_flip()]
Ans:-
slip7.html
<html>
<pre> <h3>OPERATIONS On
Array</h3>
</pre>
</form>
</body>
</html>
slip7.php
<?php
$array=array('zero'=>0,'one'=>1,'two'=>2,'three'=>3,'four'=>4,'five'=>5);
$ch=$_POST['a'];
switch($ch)
echo"key:$key val:$value.<br>";
}break;
break;
case 3 :
$len=sizeof($array);
array_splice($array,$len);
print_r( $array);
break;
case 4 :
print_r(array_flip($array));
break;
case 5 :
shuffle($array);
print_r($array);
break;
?>
Q.8 Write a menu driven PHP program to perform the following operations on associative
arrays:
a) Sort the array by values (changing the keys) in ascending, descending order.
b) Also sort the array by values without changing the keys.
Ans:
slip8.html
<html>
<body bgcolor="pink">
<input type="radio" name="ch" value=2> Sort array by values without changing key values <br>
<input type="radio" name="ch" value=3> Filter odd elements from array <br>
<input type="radio" name="ch" value=4> Sort different array at glance using single function<br>
<input type="radio" name="ch" value=8> Find set difference of two array <br>
<br>
</body>
</html>
<html>
<body bgcolor="gold">
slip8.php
<?php
function is_odd($var)
{
if($var%2==1)
return $var;
$choice=$_POST['ch'];
$arr=array('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5,'f'=>6,'g'=>7,'h'=>8);
$arr1=array('l'=>11,'m'=>22,'n'=>33,'o'=>44,'p'=>55,'q'=>66,'r'=>77,'s'=>88);
$arr2=array('a'=>10,'b'=>20,'c'=>30,'d'=>40,'e'=>50,'f'=>60,'g'=>70,'h'=>80);
switch($choice)
case 1:
sort($arr);
print_r($arr);
rsort($arr);
print_r($arr);
break;
case 2:
asort($arr);
print_r($arr);
arsort($arr);
print_r($arr);
break;
case 3:
print_r(array_filter($arr,'is_odd'));
break;
case 4:
array_multisort($arr,0,$arr1,1,$arr2,0);
print_r($arr);
echo "<br>";
print_r($arr1);
echo "<br>";
print_r($arr2);
echo "<br>";
break;
case 5:
print_r(array_merge($arr,$arr1));
break;
case 6:
print_r(array_intersect($arr,$arr1));
break;
case 7:
$union=array_merge($arr,$arr1);
print_r(array_unique($union));
break;
case 8:
print_r(array_diff($arr,$arr1));
break;
?>
</font>
</body>
</html>
Q.9 Write PHP script to define an interface which has methods area(), volume(). Define constant
PI. Create a class cylinder which implements this interface and calculate area and volume.
Ans:
slip9.html
<html>
<body>
<center>
</form>
</center>
</body>
<html>
slip9.php
<?php
$r = $_GET['r'];
$h = $_GET['h'];
define('PI','3.14');
interface cal
function area($r,$h);
function vol($r,$h);
function area($r,$h)
$area = 2*PI*$r*($r+$h);
function vol($r,$h)
$vol = PI*$r*$r*$h;
$c = new cylinder;
$c->area($r,$h);
$c->vol($r,$h);
?>
Q.10 Write class declarations and member function definitions for an employee(code, name,
designation). Design derived classes as emp_account(account_no, joining_date) from employee
and emp_sal(basic_pay, earnings, deduction) from emp_account. Write a menu driven PHP
program a) to build a master table b) to sort all entries c) to search an entry d) Display salary
Ans:-
slip10.html
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</form>
</body>
</html>
slip10.php
<?php
class employee
public $code,$name,$desig;
function __construct($a,$b,$c)
$this->code=$a;
$this->name=$b;
$this->desig=$c;
echo'
<td>'.$this->code.'</td>
<td>'.$this->name.'</td>
<td>'.$this->desig.'</td>
';
}
public function getname()
return $this->name;
public $ano,$jdate;
function __construct($a,$b,$c,$d,$e)
parent::__construct($a,$b,$c);
$this->ano=$d;
$this->jdate=$e;
echo'
<td>'.$this->ano.'</td>
<td>'.$this->jdate.'</td>
';
public $bpay,$earns,$ded,$total;
function __construct($a,$b,$c,$d,$e,$f,$g,$h)
parent::__construct($a,$b,$c,$d,$e);
$this->bpay=$f;
$this->earns=$g;
$this->ded=$h;
echo'
<td>'.$this->bpay.'</td>
<td>'.$this->earns.'</td>
<td>'.$this->ded.'</td>
<td>'.$this->total.'</td>
';
$emp[0]=new emp_sal('A923B','Ravindra','Staff','10001','21/09/2011','20000','5000','3000');
$emp[1]=new emp_sal('A823B','Kiran','HR','10002','22/09/2011','25000','5000','3000');
$emp[2]=new emp_sal('A723B','Sudhir','Analyst','10003','23/09/2011','22000','5000','3000');
$emp[3]=new emp_sal('A623B','Mahesh','Organiser','10004','24/09/2011','21000','5000','3000');
$emp[4]=new emp_sal('A523B','Ak','Manager','10005','25/09/2011','30000','5000','3000');
$emp[5]=new emp_sal('A423B','Ravi','Staff','10006','26/09/2011','20000','5000','3000');
$emp[6]=new emp_sal('A323B','Vashali','Analyst','10007','27/09/2011','21000','5000','3000');
$emp[7]=new emp_sal('A223B','Mahi','Organiser','10008','28/09/2011','21000','5000','3000');
$emp[8]=new emp_sal('A123B','Karna','Staff','10009','29/09/2011','20000','5000','3000');
$emp[9]=new emp_sal('A023B','Suraj','Staff','10010','30/09/2011','20000','5000','3000');
$ch=$_POST['rad'];
$ename=$_POST['ename'];
$flag=0;
function mastertable($emp)
<tr>
<th>Code</th>
<th>Name</th>
<th>Designation</th>
<th>Ac No</th>
<th>Join date</th>
<th>Basic Pay</th>
<th>Earnings</th>
<th>Deduction</th>
<th>Total Salary</th>
</tr>';
for($i=0;$i<10;$i++)
echo '<tr>';
$emp[$i]->display_emp();
$emp[$i]->display_acc();
$emp[$i]->display_sal();
echo '</tr>';
echo '</table>';
switch($ch)
case 1:
mastertable($emp);
break;
function srt($a,$b)
return strcmp($a->code,$b->code);
usort($emp,"srt");
mastertable($emp);
break;
for($i=0;$i<10;$i++)
$temp=$emp[$i]->getname();
if($temp==$ename)
$flag=1;
break;
if($flag==0)
else
}
break;
<tr>
<th>Employee Name</th>
<th>Basic Pay</th>
<th>Earnings</th>
<th>Deduction</th>
<th>Total Salary</th>
</tr>';
for($i=0;$i<10;$i++)
echo '<tr>
<td>'.$emp[$i]->getname().'</td>
';
$emp[$i]->display_sal();
break;
?>
Q.11 Derive a class square from class Rectangle. Create one more class circle. Create an interface
with only one method called area(). Implement this interface in all the classes. Include appropriate
data members and constructors in all classes. Write a PHP program to accept details of a square,
circle and rectangle and display the area.
Ans:
slip11.html
<html>
<body bgcolor=#84E433>
<pre>
<h1>Circle:</h1>
<h1>
square:</h1>
<h1>
Rectangle:
</h1>
</pre>
</form>
</body>
</html>
slip11.php
<html>
<body>
<?php
$p=$_POST['p'];
$q=$_POST['q'];
$n=$_POST['n'];
$m=$_POST['m'];
interface one
function area($n,$m);
function area($n,$m)
$area=$n*$m;
echo"Area of rectangle......:".$area;
echo"<br><BR>";
function area($q,$q1)
$area=$q*$q1;
echo"Area of Square.........:".$area;
echo"<BR><br>";
class circle
function area($p)
{
$area=0.5*$p*$p;
echo"Area of circle.........:".$area;
echo"<br><BR>";
$o=new rect();
$o->area($n,$m);
$s=new square();
$s->area($q,$q);
$c=new circle();
$c->area($p);
echo "<br>";
?>
</body>
</html>
Q.12. Write PHP Script to create a class account (accno,cust_name). Derive two classes from
account as saving_acc(balance, min_amount) and current_acc(balance, min_amount). Display a
menu a) Saving Account b) Current Account For each of this display a menu with the following
options. 1. Create account 2. Deposit 3. Withdrawal
Ans:
slip12.html
<!DOCTYPE html>
<html>
<body>
<select id="saving">
<option value="create">Create</option>
<option value="deposite">Deposit</option>
<option value="withderw">Withderw</option>
</select>
</form>
</body>
</html>
slip12.php
<!DOCTYPE html>
<html>
<body>
<?php
class Account {
public $acc_no;
public $acc_name;
$this->acc_name = $acc_name;
$this->acc_no = $acc_no;
public $blance;
public $min_amount;
$this->acc_no = $acc_no;
$this->blance = $blance;
$this->min_amount = $min_amount;
echo"<table border='2'>";
echo"<tr><td>Account Name</td><td>Account
no</td><td>balance</td><td>min_balance</td></tr>";
echo "<tr><td>{$this->acc_name}</td>";
echo "<td>{$this->acc_no}</td>" ;
echo"<td>{$this->blance}</td>";
echo"<td>{$this->min_amount}</td></tr>";
public $blan;
public $min_amt;
$this->acc_name = $acc_name;
$this->acc_no = $acc_no;
$this->blan = $blan;
$this->min_amount = $min_amount;
echo "<td>{$this->acc_no}</td>" ;
echo "<td>{$this->blan}</td>";
echo"</table>";
$saveing_acc->intro();
$current_acc=new current_acc("Kiran",2222,100000,1000);
$current_acc->intro();
?>
</body>
</html>
Q.13 Implement calculator to convert distances between (both ways) miles and kilometres. One
mile is about 1.609 kilometres. User interface (distance.html) has one text-input, two radio-
buttons, submit and reset -buttons. Values are posted to PHP-script (distance.php) which
calculates the conversions according the user input.
Ans:
slip13.html
<html>
<body>
<center>
<br/>
</form>
</center>
</body>
<html>
slip13.php
<?php
$distance=$_POST['distance'];
$units=$_POST['units'];
if($units=='kms'){
$miles=$distance/1.60934;
}else{
$kms=$distance*1.60934;
?>
Q. 14 Using regular expressions check for the validity of entered email-id. The @ symbol should
not appear more than once. The dot (.) can appear at the most once before @ and at the most
twice or at least once after @ symbol. The substring before @ should not begin with a digit or
underscore or dot or @ or any other special character.
Ans:
slip14.html
<html>
<body>
</form>
</body>
</html>
slip14.php
<?php
$email=$_POST['email'];
$regex = '/^[_a-z0-9-]+(\.[a-z0-9-]+)*@[a-z0-9]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
if(preg_match($regex,$email)){
else
?>
Q.15 Write PHP program to create input form for Grocery that displays List of grocery items with
checkboxes and create a bill according to list of items selected after clicking submit button.
Ans:
slip15.html
<!DOCTYPE html>
<html>
<body>
</form>
</body>
</html>
slip15.php
<?php
$hostname="127.0.0.1";
$db_name="grecery";
$username="root";
$password="";
$connection=mysqli_connect("$hostname","$username","$password","$db_name")or
die("unable to connect");
if(!$connection){
exit;
echo "<tr><td>sr.no</td><td>Name
Item</td><td>Quntity</td><td>Rate</td><td>Amount</td></tr>";
while($row=$stmt->fetch_assoc()){
echo "<tr><td>".$row['s.no']."</td>";
echo "<td>".$row['Quntity']."</td>";
echo "<td>".$row['Rate']."</td>";
echo "<td>".$row['Amount']."</td></tr>";
}
echo "</table>";
?>
INSERT INTO `bill` (`s.no`, `Name Item`, `Quntity`, `Rate`, `Amount`) VALUES
COMMIT;