0
POSTメソッドで得られた文字列と.txtファイルの文字列を比較したい。私はこれを持っているが、それはループを通過することはできないようだ...それは電子メールの一致を検索し、.txtのすべての3番目の文字列は電子メールの文字列なので、これは3回繰り返すのだ...
POSTメソッドで得られた文字列と.txtファイルの文字列を比較したい。私はこれを持っているが、それはループを通過することはできないようだ...それは電子メールの一致を検索し、.txtのすべての3番目の文字列は電子メールの文字列なので、これは3回繰り返すのだ...
<?php
/* content of emailList.txt
user_1 password_1 [email protected]
user_2 password_2 [email protected]
user_3 password_3 [email protected]
user_4 password_4 [email protected]
user_999 password_999 [email protected]
user_5 password_5 [email protected]
*/
// set POST for testing only!!
$_POST['user'] = '[email protected]';
$_POST['pass'] = 'test';
//
$email = $_POST['user'];
$email = strtolower($email);
$password = $_POST['pass'];
$filename = './emailList.txt';
// read entire file into an array, skipping empty lines and not adding return characters
$trimmed_file_array = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($trimmed_file_array AS $row) {
//print $row.'<br>';
list($f_user, $f_password, $f_email) = explode(' ', $row);
$f_email = strtolower($f_email);
if ($email === $f_email) {
print 'found user: '.$f_user.' - password: '.$f_password.' - email: '.$f_email.'<br>';
break;
}
}
?>
'in_array'を使ってください。http://php.net/manual/en/function.in-array.php – mgraph
おそらく' $ i + 3'ではなく '$ i + = 3'を意味していました。 – anubhava
それは...ありがとうございましたanubhava – ljencina77