<textarea> の値の改行コード
<textarea>
の値の改行コードは、状況によって異なります。
目次
JavaScript 上での改行コード
JavaScript 上の value (HTMLTextAreaElement の value プロパティ) で取得できる値の改行コードは LF (U+000A ラインフィード。\n
) です。
別の改行コードがあっても LF に正規化されます。
例
ここに結果が表示されます。
フォーム送信された値の改行コード
フォーム送信された値の改行コードは CRLF (U+000D キャリッジリターン / U+000A ラインフィード。\r\n
) です。
別の改行コードがあっても CRLF に正規化されます。
例 (PHP)
参考
※HTML Living Standard — Last Updated 23 August 2023
For historical reasons, the element's value is normalized in three different ways for three different purposes. The raw value is the value as it was originally set. It is not normalized. The API value is the value used in the value IDL attribute, textLength IDL attribute, and by the maxlength and minlength content attributes. It is normalized so that line breaks use U+000A LINE FEED (LF) characters. Finally, there is the value, as used in form submission and other processing models in this specification. It is normalized as for the API value, and in addition, if necessary given the element's wrap attribute, additional line breaks are inserted to wrap the text at the given width.
The application/x-www-form-urlencoded and text/plain encoding algorithms take a list of name-value pairs, where the values must be strings, rather than an entry list where the value can be a File. The following algorithm performs the conversion.To convert to a list of name-value pairs an entry list entry list, run these steps:
- Let list be an empty list of name-value pairs.
- For each entry of entry list:
- Let name be entry's name, with every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), replaced by a string consisting of U+000D (CR) and U+000A (LF).
- If entry's value is a File object, then let value be entry's value's name. Otherwise, let value be entry's value.
- Replace every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), in value, by a string consisting of U+000D (CR) and U+000A (LF).
- Append to list a new name-value pair whose name is name and whose value is value.
- Return list.
4.10.21.6 Converting an entry list to a list of name-value pairs
The multipart/form-data encoding algorithm, given an entry list entry list and an encoding encoding, is as follows:
- For each entry of entry list:
- Replace every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), in entry's name, by a string consisting of a U+000D (CR) and U+000A (LF).
- If entry's value is not a File object, then replace every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), in entry's value, by a string consisting of a U+000D (CR) and U+000A (LF).