Space for google add

= = operator & strcmp function in PHP .

 

        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)



a1setc2.html

<html>

<form action='a1setc2.php' method='post'>

Enter 1'st string :<input type='text' name='str1'><br>    

Enter 2'nd string :<input type='text' name='str2'><br> 

Enter Position :<input type='text' name='pos'><br>       

<input type='radio' name='ch' value=1>Compare<br>

        <input type='radio' name='ch' value=2>Append<br>

        <input type='radio' name='ch' value=3>Reverse<br>

        <input type=submit value= submit>

        <input type=reset value=cancel>

</form>

</body>

</html>


a1setc2.php

<?php

$s1=$_POST['str1'];

$s2=$_POST['str2'];

$pos=$_POST['pos'];

$ch=$_POST['ch'];

switch($ch)

{

case 1:

if($s1==$s2)

echo "Strings are equal.<br>";

else

echo "Strings are not equal.<br>";

if(strcmp($s1,$s2)==0)

echo "Strings are equal.<br>";

else

echo "Strings are not equal.<br>";

break;

case 2:

$a=$s1.$s2;

echo "$a";

break;

case 3:

$len=strlen($s1)-$pos;

$s=substr($s1,$pos,$len);

$str1=strrev($s);

echo "After reverese ::$str1";

break;

}

?>



Post a Comment

0 Comments