Home >Backend Development >PHP Problem >How to remove carriage return in php

How to remove carriage return in php

coldplay.xixi
coldplay.xixiOriginal
2020-09-28 13:42:303103browse

php method to remove carriage returns: 1. Use [str_replace] to replace newlines; 2. Use regular replacement; 3. Use variables defined by php, the code is [$str = str_replace(PHP_EOL, '' , $str)].

How to remove carriage return in php

php method to remove carriage returns:

php Line breaks in different systems

Different systems The implementation of line breaks is different

Use in Linux and Unix \n

Use \r in MAC

In order to reflect the difference from linux, window 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 variables defined by PHP (recommended)

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

If you want to know more about programming learning, please pay attention to the php training column!

The above is the detailed content of How to remove carriage return in php. For more information, please follow other related articles on the PHP Chinese website!

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