RE: Opening a file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<?php
$fruit = "apple";
$lines = file("fruits.txt");
if (in_array($fruit,$lines))
  {
  $a = "Y";
  }
?>

Here there may be 2 cases.
1st either file() is not returning any values, that is why array empty and
wrong datatype error, are you able to read the file.

2nd try to use implode function to consider each word as different value in
an array
$lines = implode('', file("fruits.txt"));

Warm Regards,
Sanjeev
http://www.sanchanworld.com/
http://webdirectory.sanchanworld.com - Submit your website URL
http://webhosting.sanchanworld.com - Choose your best web hosting plan

-----Original Message-----
From: Dan Shirah [mailto:mrsquash2@xxxxxxxxx] 
Sent: Wednesday, September 05, 2007 7:55 PM
To: php-general
Subject:  Opening a file

Good Morning!

Opening this file is proving to be a pain. I have a folder that contains a
PHP page and a text file. I am trying to open the contents of the txt file
using file() but it keeps erroring out. Below is the code I'm using to try
and open it:

<?php
$fruit = "apple");
$lines = file("fruits.txt");
if (in_array($fruit,$lines))
  {
  $a = "Y";
  }
?>

So, I'm setting my variable, opening my file as an array in $lines, then
checking to see if my variable is in the array, and if it is, assign a value
ot a new variable.  However, I am getting the following error:

PHP Warning: in_array()
[function.in-array<http://develop1/credit%20card%20processing/function.in-ar
ray>]:
Wrong datatype for second argument

Any ideas?

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux