PHP Remove string line break sample share _php tutorial

Source: Internet
Author: User
The 1th type of notation:
Copy CodeThe code is as follows:
Str_replace ("n", "', $str);
?>

The 2nd type of notation:
Copy the Code code as follows:
Str_replace ("RN", ", $str);
?>

The 3rd type of notation:
Copy the Code code as follows:
Preg_replace ("/s/", ", $str);
?>

The following instructions:
First of all, n,r,t.
N Soft return:
Show line breaks in Windows and go back to the beginning of the next line
The Linux/unix only represents a newline, but does not go back to the beginning of the next line
R Soft Space:
Returns to the beginning of the line in Linux/unix
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)
Additional notes:
They are valid in a double-quote or delimiter-represented string, and are not valid in a single-quote string.
RN is generally used together to indicate the return key on the keyboard (Linux,unix), or only n (windwos), in Mac OS with R to indicate carriage returns!
T means the TAB key on the keyboard
Line break symbols in the file:
Windows:n
Linux/unix:rn

The following code illustrates the three common methods of removing line breaks in a string in PHP

1. Use the escape character function
Copy the Code code as follows:
$str = Str_replace (Array ("/r/n", "/R", "/n"), "", $str);
?>

2. Replace with regular expression
Copy the Code code as follows:
$str = preg_replace ('//s*/', ' ', $str);
?>

3, the recommended use of PHP system constants
Copy the Code code as follows:
$str = Str_replace (Php_eol, ", $STR);
?>

http://www.bkjia.com/PHPjc/735240.html www.bkjia.com true http://www.bkjia.com/PHPjc/735240.html techarticle The 1th type: Copy code code as follows: PHP str_replace ("n", "', $str);? 2nd: Copy the code as follows: PHP str_replace (" rn "," ', $str);? 3rd type: Copy code ...

  • Related Article

    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.