Home > Backend Development > PHP Problem > How to remove newline characters in php

How to remove newline characters in php

王林
Release: 2023-03-06 07:00:01
Original
4387 people have browsed it

How to delete newlines in php: You can use the variable PHP_EOL defined by php, such as [str_replace(PHP_EOL, '', $str);]. You can also use regular rules to delete, such as [preg_replace('//s*/', '', $str);].

How to remove newline characters in php

Specific method:

(Recommended tutorial: php video tutorial)

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);
$str = str_replace(PHP_EOL, '', $str);
Copy after login

Related recommendations : php training

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