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

How to remove carriage return in php

coldplay.xixi
Release: 2023-03-06 07:50:02
Original
3105 people have browsed it

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);
Copy after login

2. Use regular replacement

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

3. Use variables defined by PHP (recommended)

$str = str_replace(PHP_EOL, '', $str);
Copy after login

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!

Related labels:
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