469,356 Members | 2,043 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

Display a text file on a web page

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?
Jul 17 '05 #1
6 20318
On Sat, 11 Oct 2003 10:46:20 -0700, Paul wrote:
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?

<?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.

Jul 17 '05 #2
Hello Paul,

Paul wrote:
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.


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

Jul 17 '05 #3
Eric Veltman wrote:
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 :-)


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
Jul 17 '05 #4
Eric Veltman <eric@[RemoveThis]veltman.nu> wrote in message news:<vo************@corp.supernews.com>...
Eric Veltman wrote:
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 :-)


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

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?
Jul 17 '05 #5
well , you can use <pre> tag to keep your format , like this:
$show = file("./fields/combined/$cdp$store");
$arrayitems = sizeof($show);
$x=0;
print("<pre>"); while ($x < $arrayitems) { print("$show[$x]\n");
$x++;
} print("</pre>");
pk****@yahoo.com (Paul) wrote in message news:<4c*************************@posting.google.c om>... 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?

Jul 17 '05 #6
Hello Paul,

Paul wrote:
Eric Veltman <eric@[RemoveThis]veltman.nu> wrote in message
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 :-)
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?


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
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David Thomas | last post: by
23 posts views Thread by Mat | last post: by
17 posts views Thread by kimimaro | last post: by
5 posts views Thread by David Elliott | last post: by
3 posts views Thread by jiayanxiang | last post: by
3 posts views Thread by c676228 | last post: by
9 posts views Thread by tomhawkins1 | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.