Delete textarea carriage return and line feed code

Source: Internet
Author: User
Tags php tutorial regular expression

Delete textarea carriage return and line feed code

Function removeNL (s)
// NewLine, CarriageReturn and Tab characters from a String
// Will be removed and will return the new string

R = "";
For (I = 0; I <s. length; I ++)
If (s. charAt (I )! = 'N' & s. charAt (I )! = 'R' & s. charAt (I )! ='T '){
R + = s. charAt (I );

Return r;

Php Tutorial solution

Use the php function and str_replace to replace the function, such as str_replace ('N', '<br/>'). The problem is that the replacement is not successful and has never been replaced, after a long time, I even began to doubt whether the linefeed in textarea is n. Now I think it is too shaken. In fact, after I replaced n/n separately, I intuitively told myself that I was in a dead end, this is not a way to solve the problem. There must be a fundamental error. Suddenly I thought about whether it would be a single or double quotation mark, so I changed str_replace ('N', '<br/>') to str_replace ("n ", "<br/>"). The light flashed and the replacement was successful.


Line feed (lf or ascii characters 0 × 0a (10 ))

Press enter (cr or ascii character 0 × 0d (13 ))

Horizontal Tab (ht or ascii character 0 × 09 (9 ))


Dollar Sign

Double quotation marks

[0-7] {1, 3}
This regular expression matches a character in the octal symbol.

X [0-9a-fa-f] {1, 2}
This regular expression matches a character in the hexadecimal notation.

For more details, see:

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.