Summary of solutions for removing line breaks in PHP (PHP_EOL)_PHP tutorial

WBOY
Release: 2016-07-21 15:23:09
Original
1051 people have browsed it

The first way of writing:
$content=str_replace("n","",$content);
echo $content;

The second way of writing :
str_replace("rn","",$str);

The third way of writing:
$content=preg_replace("/s/" ,"",$content);
echo $content;

Attachment:

First let’s talk about n,r,t
n Soft Enter:
In Windows Medium means a line break and returns to the beginning of the next line.
In Linux and Unix, it only means a line break, but does not return to the beginning of the next line.
r Soft space:
in Linux and unix means returning to the beginning of the current line.
In Mac OS, it means wrapping and returning to the beginning of the next line, which is equivalent to the effect of n in Windows.
t Tab (move to next column)
A few notes:
They are valid in strings represented by double quotes or delimiters, but not in strings represented by single quotes.
rn is generally used together to represent the Enter key on the keyboard (in Linux and Unix). You can also just use n (in Windows). In Mac OS, use r to represent Enter!
t represents the "TAB" key on the keyboard.
Newline symbol in file:
windows: n
linux,unix: rn
Example code:

Copy code Code As follows:

//php Line breaks in different systems
//The implementation of line breaks between different systems is different
//linux and unix Use /n
//MAC use /r
//window In order to reflect the difference from Linux, it is /r/n
//So the implementation method is different on different platforms
//php There are three ways to solve it

//1. Use str_replace to replace newlines
$str = str_replace(array("/r/n", "/r", "/n"), "" , $str);

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

//3 , use variables defined by PHP (recommended)
$str = str_replace(PHP_EOL, '', $str);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324521.htmlTechArticleThe first way to write: $content=str_replace("n","",$content); echo $content ; The second way of writing: str_replace("rn","",$str); The third way of writing: $content=preg_replace("/s/","",$content); ec...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template