Tuesday 27 February 2018

String Programs In PHP

Operations on Strings using Radio Buttons
Demo.html
<html>
<title> String Operations using functions</title>
<body style="background-color:cyan";>

<h1> Operations on Strings using Radio Buttons</h1>

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

Enter String 1 : <input type="text" name="str1"/></br>        </br>
Enter String 2 : <input type="text" name="str2" id="str2" disabled>
String to find : <input type="text" name="str3" id="str3" disabled><br></br>
Operations:</br></br>

<fieldset style="background-color:pink";>
<input type ="radio" name="operations" value="Length"  onclick="document.getElementById('str2').disabled = true;" />Length<br>

<input type ="radio" name="operations" value="Words" onclick="document.getElementById('str2').disabled = true;"/>Words<br>

<input type ="radio" name="operations" value="Reverse" onclick="document.getElementById('str2').disabled = true;"/>Reverse<br>

<input type ="radio" name="operations" value="Finding" onclick="document.getElementById('str3').disabled = false;" />Finding Text within the string<br>

<input type ="radio" name="operations" value="lowercase" onclick="document.getElementById('str2').disabled = true;"/>Converting first character of each word in a string to uppercase<br>

<input type ="radio" name="operations" value="lowercase1" onclick="document.getElementById('str2').disabled = true;"/>Converting a whole string into lowercase<br>

<input type ="radio" name="operations" value="uppercase" onclick="document.getElementById('str2').disabled = true;"/>Converting a whole string into UPPERCASE<br>

<input type ="radio" name="operations" value="compare" onclick="document.getElementById('str2').disabled = false;" />Comparing Strings<br>


<input type ="radio" name="operations" value="whitesp" onclick="document.getElementById('str2').disabled = false;"/>Removing white spaces from a String<br>

</fieldset></br>

<input type="submit" name="subtn" value="Submit"/>

</form>
</body>
</html>
stringops1.php
<?php

          $st1=$_POST['str1'];
          $ops=$_POST['operations'];
          $st2=$_POST['str2'];
          $st3=$_POST['str3'];
         
         
 if(isset($_POST['subtn']))
 {
                     
           
           if($ops=="Length")
           {
                    echo "String 1 : $st1<br> ";
                    echo"<br>Length of the Strings is ";
                    echo strlen($st1);
           }

           else if($ops=="Words")
           {
                    echo "String 1 is $st1<br> ";
                    echo"<br>No of  words in the String:  ";
                    echo str_word_count($st1);
           }

           else if($ops=="Reverse")
           {
                    echo "String 1 is $st1<br> ";
                    echo"<br>Reversing the String:  ";
                    echo strrev($st1);
                    
           }

           else if($ops=="Finding")
           {
                    echo "String 1 is $st1<br> ";
                    echo "Text to find $st3";
                    echo strpos($st1,$st3);
           }

           else if($ops=="lowercase")
           {
                    echo "String 1 is $st1<br> ";
                    echo"<br>  converts the first character of each word in a string to                               uppercase  ";
                    echo ucwords($st1);
           }

            else if($ops=="lowercase1")
           {
                    echo "String 1 is $st1<br> ";
                    echo"<br> Converting a whole string into lowercase :  ";
                    echo strtolower($st1);
           }

           else if($ops=="uppercase")
           {
                    echo "String 1 is $st1<br> ";
                    echo"<br>Converting a whole string into UPPERCASE:  ";
                    echo strtoupper($st1);
           }

           else if($ops=="compare")
           {
                            
                    echo "String 1 is $st1<br> ";
                    echo "String 2 is $st2<br> ";
                    $n=strcmp($st1,$st2);
                    if($n==0)
                    {
                              echo "Strings are equal";
                    }
                    else
                    {
                              echo "Strings are not equal";
                    }
                              
           }
           

           
      else
           {
                    echo "String 1 is $st1<br> ";
                    echo trim("$st1","$st2");
           }

 }
?>
Output:


No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...