当前位置:首页 > PHP教程 > PHP常见问题

php去除换行(回车换行)的三种方法

复制代码 代码如下:

<?php  
 //php 不同系统的换行 
//不同系统之间换行的实现是不一样的 
//linux 与unix中用 n 
//mac 用 r 
//window 为了体现与linux不同 则是 rn 
//所以在不同平台上 实现方法就不一样 
//php 有三种方法来解决 

//1、使用str_replace 来替换换行 
$str = str_replace(array("rn", "r", "n"), "", $str);  

//2、使用正则替换 
$str = preg_replace('//s*/', '', $str); 

//3、使用php定义好的变量 (建议使用) 
$str = str_replace(php_eol, '', $str);  
?> 



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!