how to replace file names with first lines?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bastler1001
Forum Newbie
Posts: 3
Joined: Sat Apr 05, 2008 5:27 am

how to replace file names with first lines?

Post by bastler1001 »

this is a news script index.php that reads the news stored as TXT files from a directory and displays the links to the TXT files. the links are actualy file names.

now it should display news headlines insted of news file names. the headline is the first line in every news TXT file. i tried to read the headlines with stream_get_line() and fgets() but only received error messages.

can you modify this code to display the news headlines as links instead of file names?

Code: Select all

<title>Plain News</title>
 
<h3>Plain News</h3>
 
<?php
# creates a link list for of the files found in the parsed directory
# require script with the function to parse directory just once, there's no need for refreshed parsing
require_once("function-parse-dir.php"); 
 
# use the parsing function 
$files = get_dir_contents('news');
 
# loop over files and make html links with vars passed on URL
foreach ($files as $file){
    echo '<a href="template.php?f=news/' . $file . '">' . $file . '</a><br />';
}
 
?>
 
<p><a href="news-admin-1.php">News Admin</a></p>
Post Reply