Home > Backend Development > PHP Tutorial > PHP替换换行符方法总结

PHP替换换行符方法总结

WBOY
Release: 2016-06-20 13:00:25
Original
836 people have browsed it

php中替换换行符的方法总结,大家都知道我们常用的两种操作系统Linux、windows中对文本的换行是不一样的,如何兼容的替换到所有的换行,php 有三种方法来解决。
  
1、使用str_replace 来替换换行

 $str=str_replace(array("\r\n","\r","\n"),"",$str);
Copy after login

2、使用正则替换

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

3、使用php定义好的变量 (建议使用)

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

 


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