473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 20638
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Thomas | last post by:
Hi there, a while ago, I posted a question regarding reading japanese text from a text file. Well, since I solved the problem, I thought I'd post my solution for the benefit of other people with...
4
by: hoke | last post by:
I want to display plain text files in the browser. The files contain html and javascript and have a .txt extension. This works fine with files with just html. Unfortunately when showing files with...
23
by: Mat | last post by:
<div id="container"> <div id="main"> <div id="header"> <p class="Address">123 Fake Street, </p> <p class="City">Crazy City, </p> <p class="Province">Ontario </p> <p class="PostalCode">H0H...
17
by: kimimaro | last post by:
How do you limits employee display where you enter the department for all the employee within that department be displayed and if lets say they are 100 or so and you have to limits 10 employee per...
5
by: David Elliott | last post by:
I need a control on a Web Page that can accept an HTML Document and will display it. Any help would be appreciated. Thanks, Dave Here is what I was trying...
3
by: jiayanxiang | last post by:
Is there any sample code to use Javascript to load and display a text file? It will be best if the user can select files using some kind of explorer. If that's complex, a text box to specify the...
3
by: c676228 | last post by:
Hi everyone, I have a piece of code in sales.aspx.vb like this: Protected WithEvents Message As System.Web.UI.WebControls.Label Try ... ChartImage.ImageUrl = "ChartGenerator.aspx?" + DataStr +...
1
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for...
9
by: tomhawkins1 | last post by:
Hi I currently have a site where users can upload files. These files can be doc, wmv, jpeg, xls, dwf, dwf and dwg. These files are uploaded to /home/**user**/uploads and not /home/...
9
by: tshad | last post by:
I have a Windows App that is doing some work and then writing a "Now Processing..." line to the status line of the window as well as the Textbox on the form. But the problem is that the work is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.