Three ways to remove line breaks in PHP

巴扎黑
Release: 2023-03-03 12:14:01
Original
1421 people have browsed it

//php Line breaks in different systems
//The implementation of line breaks is different between different systems
///n is used in linux and unix
//MAC uses /r
//window In order to reflect Different from Linux, it is /r/n
//So the implementation methods are different on different platforms
//It will be a lot of trouble to use the program you write to run on different platforms
//There are three methods in php To solve
//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)
PHP_EOL
Directly following the statement to be newlined That’s it;

Here we have to re-look at the variables that have been defined in PHP
PHP_EOL is one of them, representing the newline character of PHP. This variable will change according to the platform. Under Windows, it will be /r/n. It is /n under linux and /r under mac
$str = str_replace(PHP_EOL, '', $str);

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!