2012-04-25 11 views
0

POSTメソッドで得られた文字列と.txtファイルの文字列を比較したい。私はこれを持っているが、それはループを通過することはできないようだ...それは電子メールの一致を検索し、.txtのすべての3番目の文字列は電子メールの文字列なので、これは3回繰り返すのだ...

+0

'in_array'を使ってください。http://php.net/manual/en/function.in-array.php – mgraph

+3

おそらく' $ i + 3'ではなく '$ i + = 3'を意味していました。 – anubhava

+0

それは...ありがとうございましたanubhava – ljencina77

答えて

0
<?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; 
    } 
} 

?> 
関連する問題