Connecting Tech Pros Worldwide Forums | Help | Site Map

Display a text file on a web page

Paul
Guest
 
Posts: n/a
#1: Jul 17 '05
I have a text file that I am trying to display on a web page. If I cat
or more the file it formats and displays fine. When it comes up in the
browser it seems to loose tabs and the format gets messed up. This is
how I display the file.

$show = file("./fields/combined/$cdp$store");
$arrayitems = sizeof($show);
$x=0;
while ($x < $arrayitems) {
print("$show[$x]\n");
$x++;
}

If I edit the file it has ^M at the end of each line if it matters.
Does anyone have a better idea as to how to display it?

Ian.H
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Display a text file on a web page


On Sat, 11 Oct 2003 10:46:20 -0700, Paul wrote:
[color=blue]
> I have a text file that I am trying to display on a web page. If I cat or
> more the file it formats and displays fine. When it comes up in the
> browser it seems to loose tabs and the format gets messed up. This is how
> I display the file.
>
> $show = file("./fields/combined/$cdp$store"); $arrayitems =
> sizeof($show);
> $x=0;
> while ($x < $arrayitems) {
> print("$show[$x]\n");
> $x++;
> }
> }
> If I edit the file it has ^M at the end of each line if it matters. Does
> anyone have a better idea as to how to display it?[/color]


<?php
echo "<pre>\n";
@readfile("./fields/combined/$cdp$store");
echo "</pre>\n";
?>


HTH =)



Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.

Eric Veltman
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Display a text file on a web page


Hello Paul,

Paul wrote:
[color=blue]
> I have a text file that I am trying to display on a web page. If I cat
> or more the file it formats and displays fine. When it comes up in the
> browser it seems to loose tabs and the format gets messed up. This is
> how I display the file.[/color]

A browser ignores newlines in the source when rendering HTML.
To get a new line, you can use <BR>.

About the tabs, browsers ignore them too.
You could output table rows for each line in the file
and put what's between two tabs in a table cell.
Then the <BR> is not necessary anymore also :-)

Best regards,

Eric

Eric Veltman
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Display a text file on a web page


Eric Veltman wrote:
[color=blue]
> A browser ignores newlines in the source when rendering HTML.
> To get a new line, you can use <BR>.
>
> About the tabs, browsers ignore them too.
> You could output table rows for each line in the file
> and put what's between two tabs in a table cell.
> Then the <BR> is not necessary anymore also :-)[/color]

Sorry ... If the file is a free-format text file and not
a file with fields separated by tabs, then Ian's suggestion
is much better :-)

Best regards,

Eric
Paul
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Display a text file on a web page


Eric Veltman <eric@[RemoveThis]veltman.nu> wrote in message news:<voge382uvrhhe7@corp.supernews.com>...[color=blue]
> Eric Veltman wrote:
>[color=green]
> > A browser ignores newlines in the source when rendering HTML.
> > To get a new line, you can use <BR>.
> >
> > About the tabs, browsers ignore them too.
> > You could output table rows for each line in the file
> > and put what's between two tabs in a table cell.
> > Then the <BR> is not necessary anymore also :-)[/color]
>
> Sorry ... If the file is a free-format text file and not
> a file with fields separated by tabs, then Ian's suggestion
> is much better :-)
>
> Best regards,
>
> Eric[/color]


Actually I don't see any message from Ian about this.
The file is more like a free form document. What about the idea of
maybe trying to read the file and convert Tabs to spaces before I
display it. Does that sound possible? It would take a couple second
longer to display but at least it would look right? I think?
Easy Chen
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Display a text file on a web page


well , you can use <pre> tag to keep your format , like this:[color=blue]
> $show = file("./fields/combined/$cdp$store");
> $arrayitems = sizeof($show);
> $x=0;
> print("<pre>");[/color]
while ($x < $arrayitems) {[color=blue]
> print("$show[$x]\n");
> $x++;
> }[/color]
print("</pre>");


pkz505@yahoo.com (Paul) wrote in message news:<4c2c478e.0310110846.2faf4a1@posting.google.c om>...[color=blue]
> I have a text file that I am trying to display on a web page. If I cat
> or more the file it formats and displays fine. When it comes up in the
> browser it seems to loose tabs and the format gets messed up. This is
> how I display the file.
>
> $show = file("./fields/combined/$cdp$store");
> $arrayitems = sizeof($show);
> $x=0;
> while ($x < $arrayitems) {
> print("$show[$x]\n");
> $x++;
> }
>
> If I edit the file it has ^M at the end of each line if it matters.
> Does anyone have a better idea as to how to display it?[/color]
Eric Veltman
Guest
 
Posts: n/a
#7: Jul 17 '05

re: Display a text file on a web page


Hello Paul,

Paul wrote:
[color=blue]
> Eric Veltman <eric@[RemoveThis]veltman.nu> wrote in message[color=green]
>> Sorry ... If the file is a free-format text file and not
>> a file with fields separated by tabs, then Ian's suggestion
>> is much better :-)[/color][/color]
[color=blue]
> Actually I don't see any message from Ian about this.
> The file is more like a free form document. What about the idea of
> maybe trying to read the file and convert Tabs to spaces before I
> display it. Does that sound possible? It would take a couple second
> longer to display but at least it would look right? I think?[/color]

I guess my post arrived at your news server before Ian's post did.
Perhaps you can see Ian's post now ? Anyway, he was talking about
using the <pre>pre-formatted text</pre> trick to let the browser
display the pre-formatted text. That'll work too and is a lot easier.

Converting tabs to spaces could work also, but then you have to
choose the correct number of spaces to replace the tabs and you
will probably want to use a non-proportional font like Courier.

Best regards,

Eric
Closed Thread