473,385 Members | 1,396 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,385 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 20637
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.