Created
January 20, 2014 10:26
-
-
Save zsmynl/8517922 to your computer and use it in GitHub Desktop.
php过滤换行符的方法;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//php 不同系统的换行 | |
//不同系统之间换行的实现是不一样的 | |
//linux 与unix中用 /n | |
//MAC 用 /r | |
//window 为了体现与linux不同 则是 /r/n | |
//所以在不同平台上 实现方法就不一样 | |
//php 有三种方法来解决 | |
//1、使用str_replace 来替换换行 | |
$str = str_replace(array("/r/n", "/r", "/n"), "", $str); | |
//2、使用正则替换 | |
$str = preg_replace('//s*/', '', $str); | |
//3、使用php定义好的变量 (建议使用) | |
$str = str_replace(PHP_EOL, '', $str); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment