I am trying to read the contents of a file called 'file.txt' into an array and then compare it with the user inputs.
when I read the file it gets stored as a single line. I am trying to get a way around that but alas.
I would really appreciate any help. Thanks
--Pushpinder
HERE IS THE TEST CODE <? // These are the contents of the file "file.txt" // Note the file is exactly as it is
/*
abc111 asd123 aqw234 www234 edr234 vfr456
*/
$p_code = "abc111";
echo "The passport code that was entered in the system was $p_code<br><br>";
$PASSPORT_CODES = file("file.txt");
if(!$PASSPORT_CODES)
{
echo "File could not be read by array !! <br>";
exit;
}
else
echo "Array was opened !!<br><br>";$x = count($PASSPORT_CODES); echo "Array Count is: $x<br>";
for($j=0; $j<$x; $j++){
echo "$PASSPORT_CODES[$j]<br>";
} $A = array("\r\n", "\n\r", "\r", "\n");
$P = str_replace("$A", "\n" , "$PASSPORT_CODES");//then simple explode() the data to receive an array of lines:
$P = explode($P,"\n");
for($i=0; $i<count($P); $i++) {
if (rtrim($P[$i])==$p_code) {
$flag = "true";
echo "Congratulations, $f_name your passport code has been accepted by our system !<br><br>";
break;
}
else {
$flag = "false";
}
}if ($flag == "false") {
echo "<br> Sorry, your passport Code was not accepted by our system !<br><br>";
exit;
}
?>