Solved

display text

Posted on 2000-02-22
6
184 Views
Last Modified: 2010-03-05
i have a text file on my server but when i try to display it it can look funny

most lines are only half the width of the screen and then some lines only contain one word

example:
this is a test where i will show
what
i mean.

now this might be due to the fact that
the .txt files have a \n after certain lines.
would there be a way to display the file in html ignoring these \n's.....

thanks
0
Comment
Question by:paulwhelan
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:PC_User321
ID: 2545524
You can easily delete the lines when you read the text file, like this:-

@Lines = `cat myfile`;     # (Replace 'cat' with 'type' if on a PC)
chomp @Lines;

Now the array @Lines has the contents of myfile but with all new lines removed.  When displayed in HTML it will not have those short lines.
0
 

Author Comment

by:paulwhelan
ID: 2545558
thanks for the help
on efinal thing

now when my text is displayed i have
a scroll bar at the bottom and i have to scroll all the way over to the right to read the text

can the text be kept on the screen ( irealise that i may have to scroll down, i just dont want to scroll to the right)

is this something to do with html?

thanks
paul
0
 
LVL 5

Expert Comment

by:PC_User321
ID: 2545790
I would expect it to wrap automatically to fit the window.  I just did an experiment - I renamed a text file to x.html, and when viewed in a brouser it wrapped to fit the width of the window.  It was not necessary to remove the carriage returns.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:paulwhelan
ID: 2546241
i was using the html tags <pre> and </pre>

if i dont use the tags the text loses all paragraph infomration.

I want it to preserve everything except for the fact that i have to scroll to the right.

0
 
LVL 3

Accepted Solution

by:
monas earned 100 total points
ID: 2546813
ok, if you want text to be alligned by browser - you have to forget about <pre> - it should be html.

If you want to preserver paragraphs - then you should insert html's command for paragraph - <p>. In most cases paragraphs are separated by empty lines. - Therefore let's change all empty lines with <p>s. Code below:

open(F, "your.file");
@Lines = map {s/^\s*$/\<p\>/; $_} <F>;
close(F);

Now you can output @Lines, and say "it's HTML!"

Good Look!
0
 

Author Comment

by:paulwhelan
ID: 2546833
thats seems to have worked!
thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl match and sort unique result 2 142
How to strip .csv from file name 9 83
Regular Expression question to filter with negation. 6 100
Perl Write to Specific line in a file 15 106
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question