编辑PHP代码
<?php
$name = ($_POST['name']);
$arr = file('logs/ban_list.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$to_remove = $name;
$arr = array_filter($arr, function($item) use ($to_remove) {
return !preg_match("/$to_remove by /", $item);
});
file_put_contents('logs/ban_list.txt', join("\n", $arr));
echo "Successfully unbanned player ".$name."";
?>
在这种情况下$ name = Glenn
Log = 1036467# Glenn is banned for 0 Days Unbandate = 2014-01-02 by Glenn Banned @ 2014-01-02.
由于某种原因,它无法从txt文件ban_list.txt
中删除该字符串我不知道为什么它不起作用,如果你们能帮助我会很棒
感谢您的帮助
编辑:它必须删除整个log =行,所以
1036467 #Glenn被禁止0天Unbandate = 2014-01-02作者:Glenn Banned @ 2014-01-02
需要从ban_list.txt文件
中删除整行