Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a text area in a form this goes into a php script that outputs the text into a text file

How can i make line breaks ever time the user hits enter, by line breaks i mean the
tag, this is because the text file is read by another php script that echoes it into the document. I want it to record the users line breaks(When the user hits enter) Similar to how the text area i am using now does it. How can i do this?

EX:
Hi(enter)<br>
I am jaydman2102(enter)<br>
Posted
Updated 3-Aug-13 8:19am
v3
Comments
Zoltán Zörgő 3-Aug-13 16:18pm    
This is a simple string replacement task.
G4mm4R4y 3-Aug-13 22:22pm    
Than can you please help? Ive already searched google.
Sergey Alexandrovich Kryukov 3-Aug-13 23:03pm    
Not just this. Also <br /> won't work as a line separator inside text area. Please see my answer.
—SA
G4mm4R4y 4-Aug-13 0:19am    
Quick side question: What is the purpose of xhtml does it have any advantages besides making you code look better?

Jaydman asked:
Quick side question: What is the purpose of xhtml does it have any advantages besides making you code look better?
Huge advantage: you can validate that the code is correct using any XML parser.

Actually, you should not even play with the idea of writing some HTML code which is not well-formed XML, even if your document type is HTML and not XHTML. Working in a quick but sloppy way does not pay off. The looseness of original HTML (as compared with XML) was a considerable design mistake, in my opinion. In real life, writing such loose HTML makes no practical sense; you would not gain anything except potential troubles.

One of the possible techniques I would recommend: create all files as XHTML, validate them as you type, and, at the very end, you can rename them to HTML.

—SA
 
Share this answer
 
Comments
G4mm4R4y 4-Aug-13 1:21am    
Thanks, i have been slowing going in to xhtml while not even realizing it so this is why i asked... I figured why not go in to it but i didnt know what the advantages are. Again, thanks.
Sergey Alexandrovich Kryukov 4-Aug-13 1:27am    
Sure. Will you accept this answer formally then (green button)?
—SA
The tag <br/> works only for HTML. The text inside a text area is not really HTML, it is treated as a plain text. You need to insert new line character(s) instead. Please see: http://en.wikipedia.org/wiki/Newline[^].

As you can see, the delimiter is platform-dependent (and this is a shame of creators of those different platforms and the community who failed to agree on some standard). Fortunately, decent browsers understand separators used on different platforms.

—SA
 
Share this answer
 
Comments
G4mm4R4y 4-Aug-13 0:11am    
It doesn't HAVE to be <br> tags I just need it to read the text file that is getting its text from a text area to have line breaks were you hit enter. Your answer is unclear to me.
EDIT: I know <br> only works in html, but the text file is read by php and outputted as html
Sergey Alexandrovich Kryukov 4-Aug-13 0:14am    
Okay, I understand, but what's unclear in my answer? Just insert characters with the code point 13 (0xD), they will work as breaks.
—SA
G4mm4R4y 4-Aug-13 0:19am    
Will the user have to input them? Im so confused. I want something so when they hit submit it adds br tags or even better it adds \n and php looks for every \n and puts <br> after it so that it looks better in both php and html because it opens a text file and puts the textarea in there (The value of it) so like this
(IN A TEXTAREA)
Hello
Hi
(NOW IM NOT)
It automatically adds something to break the lines in php and html or just add br tags.. I don't know if im just repeating myself if I am please tell me.
Sergey Alexandrovich Kryukov 4-Aug-13 1:11am    
The user inputs newline characters by pressing ENTER inside text area. If you want to set value programmatically, you need to concatenate lines with newline characters.
—SA
G4mm4R4y 12-Aug-13 19:21pm    
I have a question, i know this is an old question but why was the nl2br() function mentioned?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900