Still having File trouble

From: Date: Mon, 24 Feb 2003 22:44:23 +0000
Subject: Still having File trouble
Groups: php.general 
Request: Send a blank email to php-general+get-137004@lists.php.net to get a copy of this message
Hello all, 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; } ?> RESULTS OF THE ABOVE CODE The passport code that was entered in the system was abc111 Array was opened !! Array Count is: 1 abc111 asd123 aqw234 www234 edr234 vfr456 Sorry, your passport Code was not accepted by our system ! Pushpinder Singh Garcha _________________________________ Web Architect

« previous php.general (#137004) next »