Re: file( ) function

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

 



Mayank Maheshwary wrote:
Hi,

I am facing some trouble with the file( ) function. I understand that it
returns the contents of the file in an array. Also, I am able to print the
lines using the echo function. However, whenever I try to compare the
contents of an array using strcmp, or ==, the page simply keeps 'loading',
instead of printing results.

The following is the code that I try:

$name = $_POST["filename"];
$lines = file($name);
$i = 0;
$len = sizeof($lines);
//echo $i;
while($i < $len) {
 //echo $lines[$i];
 $temp = $lines[$i];
 $temp = trim($temp);
 //echo $temp;
 if($temp1 == '--------------------------------------') {
   echo $i;
   return $i;
 }
 else
   $i++;
}

I think that the way the lines of the file are stored in the array may be
the problem, but I do not know what I am supposed to change. Any help would
be appreciated.

Thanks.

MM.


You might want to reexamine the need for your code. It appears that all your code does is searches through a file for a certain line. Do you need to do this manually? array_search() will replace your entire for loop with a single function call, and it'll almost certainly be faster to boot.

Regards, Adam Zey.

--
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