Site icon T4Tutorials.com

PHP program to compare two strings with database and flowchart

PHP program to compare two strings with database and flowchart

In this tutorial, we will learn about the followings;

  1. Flowchart to compare two strings
  2. PHP program to compare two strings.
  3. PHP program to compare two strings with form values enter by user.
  4. PHP program to compare two strings with the database.

Flowchart to compare two strings

Figure: Program of equal and unequal strings in JS Javascript form values user

PHP program to compare two strings.

<!DOCTYPE html>
<html>
<body>
<p>Click The Button to Compare The Strings.</p>
<p>Hello!</p>
<p>hello!</p>
<p>
0 - if the two strings are equal<br>
<0 - if string1 is less than string2<br>
>0 - if string1 is greater than string2<br>
</p>
</body>
</html>
<?php
	$s1="Hello!";
	$s2="hello!";
	echo strcmp($s1,$s2);
//https://www.w3schools.com/php/func_string_strcmp.asp
?>

PHP program to compare two strings with form values enter by user.

<!DOCTYPE html>
<html>
<body>
<p>Click The Button to Compare The Strings.</p>
<form method="POST" name="form1">
Enter First String.<input type="text" value="" name="str1"/>
Enter Second String.<input type="text" value="" name="str2"/>
<input type="submit" name="sub" value="Compare"/>
</form>
<p>
0 - if the two strings are equal<br>
<0 - if string1 is less than string2<br>
>0 - if string1 is greater than string2<br>
</p>
</body>
</html>
<?php
	if(isset($_POST["sub"]))
	{
		$s1=$_POST["str1"];
		$s2=$_POST["str2"];
		echo strcmp($s1,$s2);
	}
//https://www.w3schools.com/php/func_string_strcmp.asp
?>

PHP program to compare two strings with the database.

<!DOCTYPE html>
<html>
<body>
<p>Click The Button to Compare The Strings.</p>
<p>Hello!</p>
<p>hello!</p>
<p>
0 - if the two strings are equal<br>
<0 - if string1 is less than string2<br>
>0 - if string1 is greater than string2<br>
</p>
</body>
</html>
<?php
	$s1="Hello!";
	$s2="hello!";
	echo strcmp($s1,$s2);
//https://www.w3schools.com/php/func_string_strcmp.asp
?>
figure: compare two strings in PHP database.
Exit mobile version