Re: file( ) function

From: Date: Thu, 08 Jun 2006 15:44:08 +0000
Subject: Re: file( ) function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-237630@lists.php.net to get a copy of this message
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.

« previous php.general (#237630) next »