Text Box line feed display

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.