Summary of removing newline solutions in PHP (php_eol) _php Tutorial

Source: Internet
Author: User
The first type of notation:
$content =str_replace ("\ n", "", $content);
Echo $content;

The second way:
Str_replace ("\ r \ n", "", $str);

The third type of notation:
$content =preg_replace ("/\s/", "", $content);
Echo $content;

Report:

First of all, \n,\r,\t.
\ n Soft return:
Show line breaks in Windows and go back to the beginning of the next line
In Linux, Unix only represents line breaks, but does not go back to the beginning of the next line.
\ r Soft Space:
In Linux, Unix represents the return to the beginning of the line.
Represents a newline in Mac OS and returns to the beginning of the next line, equivalent to the effect of \ n in Windows.
\ t jump (move to next column)
A few notes:
They are valid in a double-quote or delimiter-represented string, and are not valid in a single-quote string.
\ r \ n generally used together, used to indicate the key on the keyboard return (Linux,unix), can also be used only \ n (windwos), in Mac OS with \ r to indicate enter!
\ t represents the "tab" key on the keyboard.
Line break symbols in the file:
Windows: \ n
Linux,unix: \ r \ n
Instance code:
Copy CodeThe code is as follows:
PHP line breaks for different systems
The implementation of line breaks between different systems is not the same
Linux and Unix with/n
MAC with/R
Window is/r/n in order to show that it is different from Linux
So the implementation method on different platforms is not the same
PHP has three ways to solve

1. Use Str_replace to replace line breaks
$str = Str_replace (Array ("/r/n", "/R", "/n"), "", $str);

2. Use regular replacement
$str = preg_replace ('//s*/', ' ', $str);

3. Use PHP-defined variables (recommended)
$str = Str_replace (Php_eol, ", $STR);
?>

http://www.bkjia.com/PHPjc/324521.html www.bkjia.com true http://www.bkjia.com/PHPjc/324521.html techarticle The first form of writing : $content =str_replace ("\ n", "", $content); Echo $content; the second: Str_replace ("\ r \ n", "", $str); The Third Way: $content =preg_replace ("/\s/", "", $content); EC ...

  • 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.