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

php 版本 5.2.4 现有一txt文件,格式如下: file.txt  

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

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

  1. $fileContent = trim(file_get_contents(‘file.txt’);
  2. $array = explode(“\r\n”, $fileContent);

并未达到预想的效果   $array => array( 0 => String(15) “1 2 3 4 5” ) 这就是问题! 解决方法:  

  1. $fileContent = trim(file_get_contents(‘file.txt’));
  2. $array = array_unique(explode(‘,’, str_replace(“\r\n”,”,”,$fileContent)));

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注