Hi Roman,
This line is your problem.
$lines = preg_replace("/\n/", "<br>", $lines);
You're replacing your newlines with <br> tags.
Your explode won't find anything because it's looking for \n 's.
Labunski wrote:
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.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php