Is it possible to read each line of data from a file?
I have a text file that has several lines on it. I only want to display the
first line only.
The
file I have
looks like this.
But outputs:
"The file I have looks like this."
Here is my code:
<?php
$dir = "path/to/files/";
// set pattern
$pattern = ".txt*|.TXT*";
// open directory and parse file list
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
echo "<div class=\"spstory\" style=\"font-family: Times New Roman, Times,
serif; font-size: 12px; width: 290px;\">
<div style=\"width: 285px; background-color: #FFFFCC; padding: 3px;\">
<span class=\"NormalHeadRed\">Breaking News</span>
<br />Please check here often for breaking news stories.
</div>
<p />
<span class=\"NomalText\">
<ul>";
// iterate over file list
while (($filename = readdir($dh)) !== false)
{
// if filename matches search pattern, print it
if (ereg($pattern, $filename))
if(strpos($filename,'.')>0)
// if ($filename = str_replace('.html','',$filename))
{
$fh = fopen($dir . $filename, 'r');
$filehead = fread($fh, 72);
fclose($fh);
echo "<li class=\"bn_bullet\"><a
href=\"/breaking_news/$filename\">".$filehead."</a></li>";
}
}
echo "</ul><p />
</span>
</div>";
// close directory
closedir($dh);
}
}
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php