I am loading text from a text file into my page. This all works fine, but it loads the text as one paragraph and not in separate lines, line breaks or paragraphs.

How can I achieve the line breaks to load the same as is the text in my text document that I load from?

Do a regular expression search for "\n" and replace with <br>. For example in perl I would do

$input =~ /\\n/<br>/g;

Don't know how you are brining in your text or what language you are working in but it can be done in any language, server side or client side.

commented: Thanks +7

why not use the <p> tag within the text? it loads to an php file right?

commented: Thanks, did that, now solved. +7

Andre

I suppose you have a text file in something like notepad, and you copy this text to paste into a "editor" of some cms type of webpage, or do you paste it into the html file of the webpage you want it to be displayed?

If it is the first (cms page editor) you can use the editor to format the text again the way you want to display it, or you can see if the editor has a "source" button to paste the text into it.

If you want to paste it into a html file, you need to code the text to the format you want, before copy it.

Remember, a .txt file is plain text, and stripped from all WYSIWYG formatting.

To code your text file, use <p> at the beginning of a paragraph, and </p> at the end of that paragraph, followed immediatly again with <p> for the next paragraph, and so on.

Thanks Kraai. My stupid browser again did not send me an email to say that I have received replies on my thread.

I have eventually solved the same as yours, I used "<p>....</p>" and it worked perfect. Thanks mate.

I have posted a new question, if you could possibly help, thanks.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.