Home >Backend Development >PHP Problem >How to remove newlines in php

How to remove newlines in php

coldplay.xixi
coldplay.xixiOriginal
2020-08-06 14:13:032825browse

php method to delete newlines: 1. Use str_replace to replace newlines, the code is [$str = str_replace(array())]; 2. Use regular replacement, the code is [$str = preg_replace('/ /s*/', '', $str)].

How to remove newlines in php

php method to delete line breaks:

php Line breaks in different systems

Between different systems The implementation of line breaks is different

Use in linux and unix \n

Use in MAC \r

window In order to reflect the difference from linux, \r\n

So the implementation methods are different on different platforms

php has three methods 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 to use )

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

Related learning recommendations: php programming (video)

The above is the detailed content of How to remove newlines 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