[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)));

发表评论

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

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax