php 读取文件内容,根据换行自动将文件内容转成array
然后循环,写入数据库.
Laravel 代码示例:
$disk = \Storage::disk('public'); $file = file_get_contents(public_path().'/senstive.txt'); $result = preg_split('/[;\r\n]+/s', $file); if(!empty($result)){ $data = []; foreach($result as $key=>$val){ if(!empty($val)){ $data[] = [ 'badword' => $val, ]; } } BadWords::insert($data); } exit;