php分割大文本成多个txt文件

2020-05-04 21:26:21 浏览数 (1)

代码语言:javascript复制
<?php
 
$content = $_POST['file'];
$arr = preg_split('/[;rn] /s',$content); //将文本分行转换成数组
$new = array_chunk($arr,40); //分割成小数组
$i = 1;
foreach ($new as $item) {
    file_put_contents($i.'.txt',implode("n",$item));
    $i  ;
}
echo "ok";

0 人点赞