Thursday, July 30, 2009

How do i list the first 6 lines of the body of a html file using php inlcuding the title of the file?

Hi





I have managed to list all html files in a directory using :





%26lt;?php


$path = "C:\Inetpub\wwwroot";


$dir_handle = @opendir($path) or die("Unable to open $path");


while ($file = readdir($dir_handle)) {


if($file == "." || $file == ".." || $file == "index.php" )


continue;


echo "%26lt;a href=\"$file\"%26gt;$file%26lt;/a%26gt;
";


}


closedir($dir_handle);


?%26gt;








now i want to list the first 5 line of the body of each html i have listed, after each file,





including the title of the html file.





I tried to add the following in my code above:





function read_logfiles($files, $lines=5)


{


foreach($files as $file_num =%26gt; $file) {


if (file_exists ($file) ) {


$handle = fopen($file, "r");


$linecounter = $lines;


$pos = -2;


$t = " ";


$text[$file_num] = "";


while ($linecounter %26gt; 0) {


while ($t != "\n") {


fseek($handle, $pos, SEEK_END);


$t = fgetc($handle);


$pos --;


}


$t = " ";


$text[$file_num] .= fgets($handle);


$linecounter --;


}


fclose ($handle);


} else {


$text[$file_num] = "The file doesn't exist.";


}


}





return $text;





?%26gt;





but it doesn't work, i get: PHP Parse error: syntax error, unexpected $end in





C:\Inetpub\wwwroot\love.php on line 42








I have read that i cant use: file_get_contents because thats for only files on network, not on my





pc, i have iis and php on windows xp.








How shall i do this


Thanks in advance





kind regards

How do i list the first 6 lines of the body of a html file using php inlcuding the title of the file?
The closing curly brace is missing ;-)





You shoul add } after return $text;


No comments:

Post a Comment