Following the password example just shown, there are many web sites today that force a person to type
there password in twice to make sure that they truly are setting it to what they want (the chances of typing it
identically wrong twice is very low). This is accomplished using such tools as strcmp() which is a built-in
to PHP.
<?php
Function chk_passwds($input1, $input2) {
if (strcomp($input1, $input2) = 0) {
print "Passwords are equal, proceed<br>";
}else {
print "Passwords are not equal<br>";
}
}
chk_passwds("doggy1", "Doggy1");
// strcmp is case-sensitive and thus these passwords are not
equal
?>
The strcomp() function has three possible results: 0 means the two strings are equal, -1 means that the first
string is less than the second string and 1 means that the second string is less than the first string. In the
example above, all that needs to be tested is if they are equal. It is not necessary to know the exact
differences between the two strings. Of course, a statement like if ($input1 == $input2) would
serve the same purpose, but would not result in the same output type.
Comments
Post a Comment