How to remove newlines in php

coldplay.xixi
Release: 2023-03-03 22:22:01
Original
2751 people have browsed it

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

2. Use regular replacement

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

3. Use variables defined by PHP (recommended to use )

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

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!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!