Summary of php methods for removing line breaks

Source: Internet
Author: User
Summary of php methods for removing line breaks

  1. $ Content = str_replace ("\ n", "", $ content );
  2. Echo $ content;

Method 2:

  1. Str_replace ("\ r \ n", "", $ str );

Method 3:

  1. $ Content = preg_replace ("/\ s/", "", $ content );
  2. Echo $ content;

Appendix -----: \ n soft carriage return: in Windows, it indicates a line break and returns to the start position of the next line. in Linux and unix, it only indicates a line break, but does not return to the start position of the next line.

\ R soft space: in Linux and unix, it indicates to return to the initial position of the row. In Mac OS, line breaks are displayed and returned to the start position of the next line, which is equivalent to \ n in Windows.

\ T hop (move to the next column)

Note: they are valid in double quotation marks or delimiters, and are invalid in single quotes. \ R \ n is generally used together to represent the carriage return key (in Linux and Unix) on the keyboard. \ n (in Windwos) can also be used only, and \ r is used to represent the carriage return in Mac OS! \ T indicates the "TAB" key on the keyboard.

File line break: windows: \ nlinux, unix: \ r \ n

There are more theories than a simple example, which can help you better understand:

  1. // Line feed for different php systems

  2. // The implementation of line feed varies with systems.
  3. // In linux and unix/n
  4. // For MAC/r
  5. // Window is/r/n to reflect differences from linux
  6. // The Implementation methods on different platforms are different.
  7. // Php has three solutions

  8. // 1. use str_replace to replace the line feed.

  9. $ Str = str_replace (array ("/r/n", "/r", "/n"), "", $ str );

  10. // 2. use regular expression replacement

  11. $ Str = preg_replace ('// s */', '', $ str );

  12. // 3. use the variables defined in php (recommended)

  13. $ Str = str_replace (PHP_EOL, '', $ str );
  14. ?>

>>> Articles you may be interested in: php removes the string line break instance parsing php compresses html (clear line breaks, clear tabs, remove comment tags) php form conversion textarea linefeed method php regular filter html tags, spaces, linefeeds, and other code examples php compress html web code (clear spaces, linefeeds, tabs, comment tags, etc) methods to provide several php replacement of line breaks php to generate excel and control the line breaks in Excel cells

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.