[php5.2.4] explode函数不能按照"\r\n"切割字符串

php 版本 5.2.4

现有一txt文件,格式如下:

file.txt

 

1
2
3
4
5


要将其内容按行分割存入数据$array中

 

执行代码:

 

$fileContent = trim(file_get_contents('file.txt');
$array = explode("\r\n", $fileContent);


并未达到预想的效果

 

$array => array(

0 => String(15) "1

2

3

4

5"

)

这就是问题!

解决方法:

 

$fileContent = trim(file_get_contents('file.txt'));
$array = array_unique(explode(',', str_replace("\r\n",",",$fileContent)));

 

 

 

posted @ 2013-04-19 22:45  javawebsoa  Views(655)  Comments(0Edit  收藏  举报