Delete textarea carriage return and line feed code

Source: Internet
Author: User
Delete textarea carriage return and line feed code: functionremoveNL (s) {NewLine, CarriageReturnandTabcharactersfromaStringwillberemovedandwillreturnthen

Delete textarea carriage return and line feed code:

  1. Function removeNL (s)
  2. {
  3. // NewLine, CarriageReturn and Tab characters from a String
  4. // Will be removed and will return the new string
  5.  
  6. R = "";
  7. For (I = 0; I <s. length; I ++)
  8. {
  9. If (s. charAt (I )! = 'N' & s. charAt (I )! = 'R' & s. charAt (I )! ='T '){
  10. R + = s. charAt (I );
  11. }
  12. }
  13.  
  14. Return r;
  15. }

Php solution:

Use the php function and str_replace to replace the function, such as str_replace ('N ','
'), The problem is that the replacement was not successful and never been replaced. after a long time, I began to doubt whether the linefeed in textarea was n. now I think it is too shaken, in fact, after I replaced n/n respectively, I intuitively told myself that I had entered a dead end. this is not a solution to the problem. there must be a fundamental error. Suddenly I thought about whether it would be a single quotation mark or double quotation mark, so the str_replace ('N ','
') Changed to str_replace ("n ","
"), The light flashed, and the replacement was successful.

Sequence description:

N: line feed (lf or ascii characters 0 × 0a (10 ))

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

T: horizontal tab (ht or ascii character 0 × 09 (9 ))

/: Backslash

$: Dollar sign

": Double quotation marks

[0-7] {}: the regular expression sequence matches a character represented by the octal symbol.

X [0-9a-fa-f] {}: this regular expression matches a character in a sequence expressed by a hexadecimal symbol.

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.