Write a PHP script for Compare the two strings, Append, string are reversed by position | PHP - IProgramX

Q.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) 



HTML File:

<html>
<head><title>   .html</title></head>
<body bgcolor="violet" >
<form action="ass1c2.php" method="post">
<pre>
                                                                                                                             
        Enter first string ::<input type="text" name="str1">
                                                                                                                             
        Enter second string::<input type="text" name="str2">
                                                                                                                             
        Enter position::<input type='text' name="pos">
                                                                                                                             
        
                        <input type="radio" name="ch" value=1>compare
                                                                                                                             
                        <input type="radio" name="ch" value=2>with datatype
                                                                                                                             
                        <input type="radio" name="ch" value=3>append.
                                                                                                                             
                        <input type="radio" name="ch" value=4>possition for reverse.
                                                                                                                             
                        <input type="submit" value="check">     <input type="reset" value="cancel">
</pre>
</form>
</body>

</html>

PHP Function:
NOTE: PHP function is saved as "ass1c2.php"


<?php
        $str1=$_POST['str1'];
        $str2=$_POST['str2'];
        $pos=$_POST['pos'];
        $ch=$_POST['ch'];
        echo"First string  :: $str1.<br><br>";
                                                                                                                             
        echo "Second string::$str2.<br><br>";
                                                                                                                             
        echo"position for reverse::$pos.<br><br>";
                                                                                                                             
        echo"choice is::$ch.<br><br>";
                                                                                                                             
        switch($ch)
        {
        case 1:
                if($str1==$str2)
                        echo"Both string are equal.<br>";
                else
                        echo"Both string are not equal.<br>";
        break;
        case 2:
                if($str1===$str2)
                        echo"Both are exat equal.<BR>";
                else
                        echo"Both are not equal.<BR>";
        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);
                echo "After reverse::$str4.<br>";
        break;
        }

?>

Output:





Post a Comment

1 Comments

  1. Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. String functions php

    ReplyDelete