Re: fgets???

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The first possible issue is that the "newline" character[s] is
different for Mac, Windows, and Linux...

So if your file is one format, and fgets is expecting the other, it
won't do what you want.

The next is that if your code is wrong, and is showing it all as one
line, it PROBABLY means you are using a browser, and you PROBABLY
aren't using nl2br to change the newlines (assuming again that nl2br
looks for the right OS newline).  Another option is "View Source" in
the browser to see the newlines.

On Fri, February 8, 2008 11:11 am, Pastor Steve wrote:
> I think I may have written the question wrong. I only want to display
> the
> first line. It is a news story with a headline. I only want to display
> the
> headline in the link.
>
> The output I want is:
>
> The
>
> But I am getting:
>
> The file looks like this.
>
> Does that make more sense?
>
> Thanks,
>
> --
> Steve M.
>
> on 2/8/08 11:03 AM Zoltán Németh (znemeth@xxxxxxxxxxxxxx) wrote:
>
>> 2008. 02. 8, péntek keltezéssel 10.54-kor Pastor Steve ezt írta:
>>> > 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."
>>
>> you need nl2br()
>> http://hu.php.net/nl2br
>>
>> greets
>> Zoltán Németh
>>
>>> >
>>> > 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);
>>> > }
>>> > }
>>> >
>>> > ?>
>>> >
>>
>
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux