473,800 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 20701
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.ne t | 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.supe rnews.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.co m (Paul) wrote in message news:<4c******* *************** ***@posting.goo gle.com>... 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
9075
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 the same problem. The plan was to make a script to read and display japanese text. I will use it for making a japanese proverb script and for a japanese language study script.
4
4143
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 javascript, I get an "error on page" warning and the page is not displayed. I suppose that when Internet Explorer discovers a <script> tag he starts to interpret it. This is not what I want. After all Internet Explorer is a browser and not an...
23
3162
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 0H0</p> <p class="Telephone">Telephone: 555-1234 </p> <p class="Fax">Fax: 555-4321</p> </div>
17
2220
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 page before entering anything to display the next 10 again?
5
15822
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
3902
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 file name will be fine as well. Once a text file is selected, I just need to display it in a text box. Thanks for the help.
3
2252
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 + "&ChartType=" + drpChartType.SelectedItem.Value.ToLower() + "&Print=" + printVersion.ToString() ... Catch e As Exception
1
3381
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 image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title>
9
2077
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/ **user**/public_html/uploads to prevent any old user from browsing them. I then use a general showDoc page with the following function (from
9
4123
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 in another class from the main class. So it couldn't access the Status Line or textbox. So what we did was set them up as properties: string IStatusDisplay.Status
0
9691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.