Write a PHP program that will compare two strings whether they are same or not.

PHP Program to compare two strings whether they are same or not in php


In this tutorial, you will learn how to compare two strings whether they are same or not in PHP. | How to Compare Two Strings in PHP

Below is the php script to compare two strings whether they are same or not in php.

<html>
<head>
    <title>PHP Program to compare two strings</title>
</head>
<body>

    <h2>PHP Script to compare two strings</h2>
   
    <form action=" " method="post">
        <input type="text" name="string1"/> <br>
        <input type="text" name="string2" /><br>
        <input type="submit" /><br>
    </form>

    <?php
    if($_POST)
    {
        $str1 = $_POST['string1'];
        $str2 = $_POST['string2'];

        echo "first String is: $str1 <br>";
        echo "Second String is: $str2 <br>";  

        if($str1==$str2)
        {
            echo "Strings are EQUAL";  
        }
        else
        {
            echo "Strings are NOT EQUAL";  
        }
    }
    ?>
   
</body>
</html>


Thanks for reading.

© Copyright - 2018 - 2022 | All rights reserved at Funda of Web IT