PHP Remove string line feed example Share _php instance

Source: Internet
Author: User

The 1th way:

Copy Code code as follows:

<?php
Str_replace ("n", ", $str);
?>

The 2nd way:

Copy Code code as follows:

<?php
Str_replace ("RN", ", $str);
?>

The 3rd way:

Copy Code code as follows:

<?php
Preg_replace ("/s/", "", $str);
?>

Here is a description:
First, n,r,t.
N Soft return:
Represents a newline in windows and returns to the beginning of the next line
Only wrap in Linux/unix, but not back to start of next line
R Soft Space:
In Linux/unix to return to the beginning of the row
The first position in the Mac OS that represents a newline and returns to the next line, equivalent to the effect of N in Windows
T-jump (move to next column)
Supplementary Note:
They are valid in double quotes or in a string represented by a delimiter, and are not valid in a string of single quotes.
RN is commonly used to represent the return key on the keyboard (Linux,unix), or only in N (Windwos), in the Mac OS with R to express enter!
T represents the TAB key on the keyboard
NewLine symbol in File:
Windows:n
Linux/unix:rn

Here's a code description of three common ways to remove line wrapping in a string in PHP

1. Use the escape character function

Copy Code code as follows:

<?php
$str = Str_replace (Array ("/r/n", "/R", "N"), ", $STR);
?>

2. Use regular expressions to replace

Copy Code code as follows:

<?php
$str = preg_replace ('//s*/', ', ', $str);
?>

3, the recommended use of PHP system constants

Copy Code code as follows:

<?php
$str = Str_replace (Php_eol, ', $str);
?>

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.