0% found this document useful (0 votes)
4 views

Assignment3 Seta

The document contains PHP scripts for two assignments involving basic arithmetic operations and string manipulation. The first assignment accepts two integers and performs operations such as modulus, power, sum of first n numbers, and factorial, while the second assignment accepts a string and allows various operations like finding length, counting vowels, converting case, padding, removing spaces, and reversing the string. Each operation is defined in separate functions and executed based on user input from HTML forms.

Uploaded by

sahilbro8698
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment3 Seta

The document contains PHP scripts for two assignments involving basic arithmetic operations and string manipulation. The first assignment accepts two integers and performs operations such as modulus, power, sum of first n numbers, and factorial, while the second assignment accepts a string and allows various operations like finding length, counting vowels, converting case, padding, removing spaces, and reversing the string. Each operation is defined in separate functions and executed based on user input from HTML forms.

Uploaded by

sahilbro8698
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

//Assignment3_seta_1

Q1.) Write a script to accept two integers(Use html form having 2 textboxes).
Write a PHP script to,
a. Find mod of the two numbers.
b. Find the power of first number raised to the second.
c. Find the sum of first n numbers (considering first number as n)
d. Find the factorial of second number.

(Write separate function for each of the above operations.)

//html

<html>

<body>

<form action="seta1.php" method="post">

Enter first number<input type="text" name="t1"><br>

Enter second number<input type="text" name=t2>

<input type="submit" value="display"></form></body></html>

//seta1.php

<?php

function mod($x,$y)

$z=$x%$y;

echo "mod value of $x & $y is $z<br>";

function power($x, $y)

$f= 1;

$n1 = $y;

while($n1 > 0)

$f= $f * $x;

$n1--;

}
echo "$x raised to the power $y = $f <br>";

function sum($x)

$sum=0;

$i=1;

while($i<=$x)

$sum=$sum+$i;

$i++;

echo "sumof first $x number is $sum<br>";

function fact($y)

$i=1;$f=1;

while($i<=$y)

$f=$f*$i;

$i++;

echo "factorial of $y is $f";

$x=$_POST['t1'];

$y=$_POST['t2'];

mod($x,$y);

power($x,$y);

sum($x);

fact($y);

?>

Q2.) Write a PHP script to accept 2 strings from the user, the first string should be a sentence and
second can be a word.
a. Delete a small part from first string after accepting position and number of characters to
remove.
b. Insert the given small string in the given big string at specified position without removing any
characters from the big string.
c. Replace some characters/ words from given big string with the given small string at specified
position.
d. Replace all the characters from the big string with the small string after a specified position.

(Use substr_replace() function)

<html>

<body>

<form action="seta2_1.php" method="POST">

Enter string<input type="text" name="txt1"><br>

Enter your choice<br>&nbsp&nbsp

Find Length<input type="radio" name="op" value="len"> <br>

count Vowels<input type="radio" name="op" value="Vowels"> <br>

convertcase<input type="radio" name="op" value="convert"><br>

pad the string<input type="radio" name="op" value="pad"><br>

Remove leading white spaces<input type="radio" name="op" value="sp"><br>

reverse th string<input type="radio" name="op" value="rev"><br>

<input type="submit" value="check">

</form>

</body>

</html>

//seta2_1.php

<?php

include("seta2_2.php");

$x=$_POST['txt1'];

$y=$_POST['op'];

if($y=="len")

getlength($x);
}

else if($y=="Vowels")

vowel($x);

else

if($y=="convert")

change($x);

else

if($y=="pad")

padding($x);

else

if($y=="sp")

remove($x);

else

if($y=="rev")

reverse($x);
}

else

echo"invalid choice";

?>

//seta2_2.php

<?php

function getlength($s)

echo "length of string is".strlen($s)."<br>";

function vowel($s)

$cnt=0;

for($i=0;$i<strlen($s);$i++)

if($s{$i}=='a'||$s{$i}=='e'||$s{$i}=='i'||$s{$i}=='o'||$s{$i}=='u')

$cnt++;

echo "total number os vowels are".$cnt;

function change($s)

echo "lowercase of string".strtolower($s)."<br>";

echo "upper case of string is".strtoupper($s)."<br>";

function padding($s)

$p=str_pad($s,15,"*",STR_PAD_BOTH);

echo "padded string is".$p."<br>";

function remove($s)

{
echo "after removing white spaces from begining".ltrim($s);

function reverse($s)

echo "after reverse the string".strrev($s);

?>

You might also like