My only remaining thought is that if the file looks like it has line breaks
when you open it then it must have line breaks of some kind.  You could
experiment with \r and \n\r by reading the file into a variable and then
explode("\n\r",$file) to see if that creates the array for you.  Other than
that I'm at a loss.  I'd be happy to experiment with the raw file if you
care to post it.

- Kevin

----- Original Message -----
From: "Pushpinder Singh Garcha" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, February 24, 2003 3:44 PM
Subject: [PHP] Still having File trouble


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




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to