Home >Backend Development >PHP Tutorial >when you say nothing at all Summary of solutions to remove line breaks in PHP (PHP_EOL)

when you say nothing at all Summary of solutions to remove line breaks in PHP (PHP_EOL)

WBOY
WBOYOriginal
2016-07-29 08:47:181170browse

The first way of writing:
$c
echo $content;
The second way of writing:
str_replace("rn","",$str);
The third way of writing:
$c/s/","", $content);
echo $content;
Attachment:
First let’s talk about n, r, t
n Soft return:
In Windows, it means a line break and return to the beginning of the next line.
Only in Linux and unix. Wrap, but not return to the beginning of the next line.
r Soft space:
In Linux, unix, it means returning to the beginning of the current line.
In Mac OS, it means wrapping and returning to the beginning of the next line. Equivalent to the effect of n in Windows.
t Tab (move to the 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), or just n (in Windows). In Mac OS, r is used to represent Enter!
t represents the "TAB" on the keyboard. " key.
Newline symbol in the file:
windows: n
linux, unix: rn
Example code:

Copy code The code is as follows:


//php Newline for different systems
//The implementation of line breaks is different between different systems
///n is used in linux and unix
///r is used in MAC
//window In order to reflect the difference from linux, it is /r/n
//So The implementation methods are 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 php to define it Variable (recommended)
$str = str_replace(PHP_EOL, '', $str);
?>

The above has introduced a summary of the solution for removing line breaks in PHP when you say nothing at all (PHP_EOL), including the content of when you say nothing at all. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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