Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What character represents a new line in a text area

Just quick one, but want to make sure I'm catching cross platform variations.

I like to convert new lines entered into a text area into a [comma], so that the output can be represented on a single line, my question...

Currently, sending from google chrome, when I view the value, I find it uses \r\n for new lines. If I replace \r\n I know it will work for chrome on windows 7, but what about other platforms, are there variations on what other browsers will insert as a new line inside a text area?

like image 252
Ninjanoel Avatar asked Jan 08 '13 14:01

Ninjanoel


People also ask

How do you represent a new line?

In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF.

How do you make a new line in textarea?

To add line breaks to a textarea, use the addition (+) operator and add the \r\n string at the place where you want to add a line break, e.g. 'line one' + '\r\n' + 'line two' . The combination of the \r and \n characters is used as a newline character.

What is the character for line break?

LF (character : \n, Unicode : U+000A, ASCII : 10, hex : 0x0a): This is simply the '\n' character which we all know from our early programming days. This character is commonly known as the 'Line Feed' or 'Newline Character'.

What is new line character in HTML?

<br>: The Line Break element. The <br> HTML element produces a line break in text (carriage-return).


1 Answers

By HTML specifications, browsers are required to canonicalize line breaks in user input to CR LF (\r\n), and I don’t think any browser gets this wrong. Reference: clause 17.13.4 Form content types in the HTML 4.01 spec.

In HTML5 drafts, the situation is more complicated, since they also deal with the processes inside a browser, not just the data that gets sent to a server-side form handler when the form is submitted. According to them (and browser practice), the textarea element value exists in three variants:

  1. the raw value as entered by the user, unnormalized; it may contain CR, LF, or CR LF pair;
  2. the internal value, called “API value”, where line breaks are normalized to LF (only);
  3. the submission value, where line breaks are normalized to CR LF pairs, as per Internet conventions.
like image 56
Jukka K. Korpela Avatar answered Sep 19 '22 09:09

Jukka K. Korpela