Home >Backend Development >PHP Problem >How to remove newlines in php
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)].
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!