//输入需要筛选的文件路径
$filepath = "_chat.txt";
if (!file_exists($filepath)) {
echo "文件不存在";
} else {
//将文件内容以字符串形式读取
// $str = file_get_contents($filepath);
// 以数组形式读取文件
$file_arr = file($filepath);
$one = [];
for($i=0; $i<count($file_arr); $i++)
{//逐行读取文件
$str1 = $file_arr[$i];
// strpos寻找字符串中 含有“+1”的数组
if(strpos($str1,"+1")!== false)
{
//将字符串抽取 为新的数组
array_push($one, $str1);
}else{}
}
// 数组转字符串
implode(',',$one);
//将newname.txt文件输出
file_put_contents('newname.txt',$one);
}