Replacing line breaks in PHP _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Summary of replacing line breaks in PHP. Methods for replacing line breaks in PHP summary methods for replacing line breaks in php. There are three solutions for php. 1. use str_replace to replace the line feed $ strstr_replace (array (rn, r, PHP ).

In summary, there are three methods for replacing line breaks in php.

1. use str_replace to replace the line feed.

$str=str_replace(array("\r\n","\r","\n"),"",$str);

2. use regular expression replacement

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

3. use variables defined in php (recommended)

$str=str_replace(PHP_EOL,'',$str);

Switch to a line feed that can be displayed on the front-end. for directions of the nl2br, refer to the php Manual.

$str="abefc";echo nl2br($str);

The output html code is as follows:

A

B

E

F

C

Articles you may be interested in
  • Php uses regular expressions to filter various tags, spaces, and line breaks.
  • How does php convert the br line breaks in html to line breaks in text input?
  • PHP compresses html webpage code (clear spaces, line breaks, tabs, comment tags)
  • Css controls code for force-breaking and non-wrapping in English and Chinese
  • Php string replacement function str_replace is faster than preg_replace
  • PHP is replaced only once to control the number of replacements
  • PHP compresses html webpage code to reduce the amount of network data transmitted, clear spaces, tabs, and comment mark
  • In php, we use the curl post method to submit data and the get method to obtain webpage data.

In summary, there are three methods to replace line breaks in Composer php. 1. use str_replace to replace the newline $ str = str_replace (array ("\ r \ n", "\ r ","\...

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.