162. PHP Program to compare two strings are same or not.
How does this program work?
- This program is used to compare two strings are same or not using PHP.
- By using if condition we can compare the given two strings.
Here is the code
<html>
<head>
<title> PHP Program To compare two strings are same or not</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num1" value="" placeholder="Enter first String"/> </td>
</tr>
<tr>
<td> <input type="text" name="num2" value="" placeholder="Enter second String"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit'])) {
$s1 = $_POST['num1'];
$s2 = $_POST['num2'];
echo "First String: ".$s1."</br>";
echo "Second String: ".$s2."</br>";
//Compare two Strings
if ($s1 == $s2) {
echo 'Both strings are equal';
}
else
{
echo 'Both strings are not equal';
}
return 0;
}
?>
</body>
</html>