[Problem] - reading file
| From: | Labunski | Date: | Mon, 06 Feb 2006 19:15:34 +0000 |
| Subject: | [Problem] - reading file | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-229979@lists.php.net to get a copy of this message | ||
Hello,
The problem is, that script outputs Last line from the file (and not first
line, as expected)!
4 hours spent seeking for mistake. Hopeless.
The script should read all the filenames in the directory,
then open each file to read first line from file and output this line.
if(!isset($_GET['id'])){//if !ISSET ID
$path = "files/info/".LANG;
if ($handle = opendir($path)) {//first if
while (false !== ($file = readdir($handle))) { //while
if ($file != "." && $file != "..") { //if not . ..
if(!is_file($file)){
//echo $file."<br><br>";
$new_path = "files/info/".LANG."/".$file;
//echo $new_path;
$text = file($new_path);
foreach($text as $lines ) {
$lines = preg_replace("/\n/", "<br>", $lines);
$lines = trim($lines);
$lines = explode("\n",$lines);
$out = "$lines[0]";
}
echo $out."<br><br>";
unset ($out);
}//!is_file
}//if not . ..
}//while
closedir($handle);
}//first if
}//if !ISSET ID
If text files look like:
1.txt{
First line of 1.txt.
Second line of 1.txt.
}
2.txt{
First line of 2.txt.
Second line of 2.txt.
}
Then Output (using this script) will be:
Second line of 1.txt
Second line of 2.txt
- - - - - - - - - - -
But it should be:
First line of 1.txt
First line of 2.txt
I'm really hopeless..
Thanks everyone in advance!
Roman.