.htgroup 文件示例:
admin: user2
editor: user1 user3
writer: user3
class Htgroup { private $file = ''; private function write($groups = array()) { $str = ''; foreach ($groups as $group => $users) { $users_str = ''; foreach ($users as $user) { if (!empty($users_str)) { $users_str .= ' '; } $users_str .= $user; } $str .= "$group: $users_str\n"; } file_put_contents($this -> file, $str); } private function read() { $groups = array(); $groups_str = file($this -> file, FILE_IGNORE_NEW_LINES); foreach ($groups_str as $group_str) { if (!empty($group_str)) { $group_str_array = explode(': ', $group_str); if (count($group_str_array) == 2) { $users_array = explode(' ', $group_str_array[1]); $groups[$group_str_array[0]] = $users_array; } } } return $groups; } public function __construct($file) { if (file_exists($file)) { $this -> file = $file; } else { die($file." doesn't exist."); return false; } } public function addUserToGroup($username = '', $group = '') { if (!empty($username) && !empty($group)) { $all = $this -> read(); if (isset($all[$group])) { if (!in_array($username, $all[$group])) { $all[$group][] = $username; } } else { $all[$group][] = $username; } $this -> write($all); } else { return false; } } public function deleteUserFromGroup($username = '', $group = '') { $all = $this -> read(); if (array_key_exists($group, $all)) { $user_index = array_search($username, $all[$group]); if ($user_index !== false) { unset($all[$group][$user_index]); if (count($all[$group]) == 0) { unset($all[$group]); } $this -> write($all); } } else { return false; } } }
$groupHandler = new Htgroup('/home/myuser/.htgroup'); // Add user 'user1' to group 'admin' in .htgroup. Group will be automatically created if it doesn't exist. $groupHandler -> addUserToGroup('user1', 'admin'); // Delete user 'user1' from group 'admin' in .htgroup. Group will be automatically removed if it doesn't contain any users. $groupHandler -> deleteUserFromGroup('user1', 'admin');
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
4 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
4 周前By尊渡假赌尊渡假赌尊渡假赌
刺客信条阴影:贝壳谜语解决方案
2 周前ByDDD
R.E.P.O.如果您听不到任何人,如何修复音频
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
1 个月前By尊渡假赌尊渡假赌尊渡假赌

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

Dreamweaver Mac版
视觉化网页开发工具

记事本++7.3.1
好用且免费的代码编辑器