thinkphp5 读取多行文本、读取文件分割多行文本

2023-08-08 14:35:28 浏览数 (1)

读取文本

代码语言:javascript复制
public function daoru(){
/*
 * 逐行读取TXT文件 
 */
 
        $rep = str_replace("n", ',', "TD92069E76EC27CA8B66B631CB49A9C6
TD5A22D898050393C2F8D5C29C854F1B");
        $cont = explode(',', $rep);
        for ($i = 0;$i < count($cont);$i  ) {
            // $data = ['code' => $cont[$i], 'status' => 0, 'time' => time() ];
             echo $cont[$i];
             echo "===";
           
        }
        
        // var_dump($data);
}

读取文件:

代码语言:javascript复制
public function daoru(){
/*
 * 逐行读取TXT文件 
 */
 


$file_='file/122.txt';
 $file = file_get_contents($file_);
        $rep = str_replace("rn", ',', $file);
        $cont = explode(',', $rep);
        for ($i = 0;$i < count($cont);$i  ) {
            // $data = ['code' => $cont[$i], 'status' => 0, 'time' => time() ];
             echo $cont[$i];
             echo "===";
           
        }
}

0 人点赞