After the text box textarea inputs content in the HTML webpage, The linefeed n is not visible to the naked eye, and the HTML display cannot convert n to linefeed. Because the label tag for line feed in HTML is br, the content of textarea should be converted once. If the content in textarea is copied from a program on windows
The linefeed \ n in the text box textarea cannot be seen by the naked eye after the content is entered in the HTML webpage, and \ n cannot be converted to a linefeed When HTML is displayed. Because the label tag for line feed in HTML is br/, the content of textarea should be converted once. If the content in textarea is copied from a program on windows
The linefeed \ n in the text box textarea cannot be seen by the naked eye after the content is entered in the HTML webpage, and \ n cannot be converted to a linefeed When HTML is displayed. Because the line feed tag in HTML is
So the content of textarea should be converted once.
If the content in textarea is copied from a program on windows, there may be a carriage return \ r in the content, which is not displayed in HTML, in Linux, \ n represents a line break, while \ r \ n is another line in Windows.
PHP conversion text box content
Convert each row of data in the text box to a PHP array:
If a form is submitted from Windows and stored to the database:
$ Array = explode ("\ r \ n", $ textarea );
If the operation is performed in Linux or stored in the database in Ajax mode without the carriage return \ r, use this method and this method is compatible with the previous method:
$ Array = explode ("\ n", $ textarea );
Use the linefeed \ n to split the array. It should be compatible with all operations.
Convert the content in the text box to the PHP variable and display it in HTML:
In HTML, only
Is a line break, so the line break is converted
:
$ Body = str_replace (array ("\ r \ n", "\ n "),"
", $ Textarea_content );
Use PHP str_replace to replace.
JavaScript conversion text box content
In HTML, only
Is a line break, so the line break is converted
:
Var textarea_content = $ ("textarea"). val ();
GetDisplayText (textarea_content );
// Replace line breaks and spaces
Function getDisplayText (str ){
Str = str. replace (/\ r/g ,"");
Str = str. replace (/\ t/g ,"");
Str = str. replace (/\ n/g ,"
");
Return str;
}
Use the replace function of JS to replace.
Application Cases
(...)
Read the rest of text box line feed display (1 words)
©Lixiphp for LixiPHP, 2013. | Permalink | No comment | Add to del. icio. us
Post tags: html, JavaScript, PHP, textarea, \ r \ n, line feed, text box
Feed enhanced by Better Feed from Ozh