Saturday, June 27, 2015

Assignment 1 Question 2 (Server Side Scripting Part using PHP).

<?php
/*
@autor Rajendra Kumar Yadav
@Check the Substring position
@Check First and last occurance Position
@ Replace Small Substring with some new substring.
*/

$n=$_POST['str1'];
$n1=$_POST['str2'];
$n2=$_POST['str3'];
$ch=$_POST['ch'];
function POSITION($n,$n1)
{
$c=strpos($n,$n1);
$c1=strrpos($n,$n1);
echo "The Substring 2 Occurs at position ".$c." and ".$c1;
}
function OCCUR_SUBSTR($n,$n1)
{
$c2=substr_count($n,$n1);
echo "The Substring ".$n1 ." occured ".$c2." times.";
}

if($ch=="first_last_pos")
{
POSITION($n,$n1);
}
if($ch=="occ_substring")
{
OCCUR_SUBSTR($n,$n1);
}
function REPLACER($n,$n1,$n2)
{
$c3=strlen($n1);
$c4=substr_replace($n,$n2,$c,$c3);
echo "First String is ".$n;
echo "Second String is ".$n1;
echo "New String is ".$n2;

}
if($ch=="replacer")
{
REPLACER($n,$n1,$n2);
}

?>

No comments :

Post a Comment