strcmp function
Posted: Tue Jul 26, 2005 5:09 pm
strcmp is a function that some people may not know about; it is a binary safe string comparison:
As you can see, the function could be useful in a simple password comparison. It can also detirmine if numbers are greater or smaller than each other.
For more info: www.php.net/strcmp
Code: Select all
<?
// Set up variables
$password = "rand0m";
$subpass = "rand0m";
// Use function, will return true
if (strcmp($password, $subpass) == 0) { #if the functions are the same, it will return 0
echo "These strings are equal<br>";
}
else {
echo "These strings are not equal<br>";
}
// Unequal
$password = "sprand0m";
if (strcmp($password, $subpass) == 0) { will not return 0
echo "These strings are equal";
}
else {
echo "These strings are not equal";
}
?>For more info: www.php.net/strcmp