Latest Lists

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 : <?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 "<a href=\"$file\">$file</a><br />"; } closedir($dir_handle); ?> 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 => $file) { if (file_exists ($file) ) { $handle = fopen($file, "r"); $linecounter = $lines; $pos = -2; $t = " "; $text[$file_num] = ""; while ($linecounter > 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; ?> 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

Public Comments

  1. The closing curly brace is missing ;-) You shoul add } after return $text;
Powered by Yahoo! Answers