strcmp function
Posted: Wed Jul 27, 2005 12:09 am
strcmp is a function that some people may not know about; it is a binary safe string comparison:
[code]<?
// 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";
}
?>[/code]
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]<?
// 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";
}
?>[/code]
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