zoukankan      html  css  js  c++  java
  • [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)));
  • 相关阅读:
    libusbwin32
    KMP
    windows.h
    iomanip
    C++继承
    LIST
    fstream
    VS2010中调试c++程序的方法
    sstream
    char 与char* 字符串与字符
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3031692.html
Copyright © 2011-2022 走看看