备忘常用方法  

1.寻找子栏目(权限\菜单列表。。。)


  function getSon($list,$pid){


    $arr='';
foreach ($list as $k=>$v){
if($v['pid']==$pid){
$v['son']=getSon($list,$v['id']);
$arr[]=$v; } }
return
$arr;
}

2.删除文件
private function _deleteDir($R){
//打开一个目录句柄
$handle = opendir($R);
//读取目录,直到没有目录为止
while(($item = readdir($handle)) !== false){
//跳过. ..两个特殊目录
if($item != '.' and $item != '..'){
//如果遍历到的是目录
if(is_dir($R.'/'.$item)){
//继续向目录里面遍历
$this->_deleteDir($R.'/'.$item);
}else{
//如果不是目录,删除该文件
if(!unlink($R.'/'.$item))
die('error!');
}
}
}
//关闭目录
closedir( $handle );
//删除空的目录
return rmdir($R);
}

3.正则匹配百度首页logo地址

//获取百度logo图片地址
$url="https://www.baidu.com";
$f=file_get_contents($url);
preg_match_all("<img.*?src=\"(.*?.*?(logo).*?)\".*?>",$f,$match);
foreach($match[1] as $val){
echo $val;
echo "</br>";
}

3.1   常见邮箱验证规则:^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$


4.图片上传

function saveAvatar($content) {
global $_W;
if (empty($content)) {
$this->exitJson("图片未找到", 1);
}
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $content, $result)) {
$type = $result[2];
$img = base64_decode(str_replace($result[1], '', $content));
} else {
$img = base64_decode($content);
$type = "jpg";
}
$fileUrl = "attachment/images/" . $_W['uniacid'] . "/" . date("Y") . "/" . date("m") . "/";
if(!is_dir(IA_ROOT ."/".$fileUrl)){
mkdir(IA_ROOT ."/".$fileUrl,0777);
}
$imageName = random(15) . time() . "." . $type;
$size = file_put_contents(IA_ROOT . "/" . $fileUrl . $imageName, $img);
if ($size > 2 * 1024 * 1024) {
$this->exitJson("图片过大!", 1);
}
return $_W['siteroot'] . $fileUrl . $imageName;
} 5.查找下级id(递归)
function getSubs($id, $includeSelf = true){
static $ids = [];
if($includeSelf) {
if(!in_array($id, $ids)) {
array_push($ids, $id);
}
}
$subIds = M('user')
->field('user_id')
->select();
$subIds = array_column($subIds, 'user_id');
$ids = array_unique(array_merge($ids, $subIds));
foreach($subIds as $sub_id) {
getSubs($sub_id, $includeSelf);
} return $ids;
}

5.2 递归查找下级(循环)

function getSubIds($userID, $includeSelf = true){
$userIDs = [$userID];
while (true) {
$subIDs = M('user')
->field('user_id')
->where(['pid' => ['IN', $userIDs]])
->select();
$subIDs = array_column($subIDs, 'user_id');
$userCount = count($userIDs);
$userIDs = array_unique(array_merge($userIDs, $subIDs));
if ($userCount == count($userIDs)) {
break;
}
}
if (!$includeSelf) {
for ($i = 0; $i < count($userIDs); ++$i) {
if ($userIDs[$i] == $userID) {
array_splice($userIDs, $i, 1);
break;
}
}
} return $userIDs;
}

6. php 命令行下执行定时任务:php index.php /crontab/index/cron

  

7. 判断是不是同一条线的用户

/**
* 检测是不是同一条线
* @param $uid
* @param $pid
* @param int $depth
* @return bool
*/
function checkIsBelong( $uid , $pid , $depth = )
{ if ( $uid == $pid && $depth > ) {
return true;
} $uid = query_user ( $uid , 'ue_accname' );
if ( !empty($uid) ) {
return checkIsBelong ( $uid , $pid , $depth + );
} return false;
} //获取用户信息
function query_user( $uid , $field = false )
{
$model = M ( 'user' );
if ( $field ) {
$arr_info = $model->field ( $field )->where ( [ 'UE_account' => $uid ] )->find ();
return $arr_info[ $field ];
} else {
$arr_info = $model->where ( [ 'UE_account' => $uid ] )->find ();
return $arr_info;
}
}
 

php工具方法的更多相关文章

  1. JQuery操作类数组的工具方法

    JQuery学习之操作类数组的工具方法 在很多时候,JQuery的$()函数都返回一个类似数据的JQuery对象,例如$('div')将返回div里面的所有div元素包装的JQuery对象.在这中情况 ...

  2. jQuery工具方法

    目录 常用工具方法 判断数据类型的方法 Ajax操作 $.ajax 简便写法 Ajax事件 返回值 JSONP 文件上传 参考链接 jQuery函数库提供了一个jQuery对象(简写为$),这个对象本 ...

  3. jQuery晦涩的底层工具方法们

    这里整理的是jQuery源码中一些比较晦涩难懂的.内部的.最底层的工具方法,它们多为jQuery的上层api方法服务,目前包括: jQuery.access jQuery.access: functi ...

  4. angular的工具方法笔记(equals, HashKey)

    分别是angular脏值检测的工具方法equals和 类HashKey的使用方法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transi ...

  5. zepto源码学习-02 工具方法-详细解读

    上一篇:地址 先解决上次留下的疑问,开始看到zepto.z[0]这个东西的时候,我很是不爽,看着它都不顺眼,怎么一个zepto的实例对象var test1=$('#items');  test__pr ...

  6. jQuery源代码 解析一 工具方法

    1. 外层沙箱以及命名空间$ 几乎稍微有点经验前端人员都这么做,为了避免声明了一些全局变量而污染,把代码放在一个"沙箱执行",然后在暴露出命名空间(可以为API,函数,对象): 2 ...

  7. Underscore.js 常用类型判断以及一些有用的工具方法

    1. 常用类型判断以及一些有用的工具方法 underscore.js 中一些 JavaScript 常用类型检查方法,以及一些工具类的判断方法. 首先我们先来谈一谈数组类型的判断.先贴出我自己封装好的 ...

  8. 秒味课堂Angular js笔记------Angular js中的工具方法

    Angular js中的工具方法 angular.isArray angular.isDate angular.isDefined angular.isUndefined angular.isFunc ...

  9. javascript 的工具方法 --- 类型判断

    Javascript中常见类型对象有: Boolean, Number, String, Function, Array, Date, RegExp, Object, Error, Symbol等等. ...

  10. JavaScript 深入学习及常用工具方法整理 ---- 01.浮点数

    在JavaScript中是不区分整数值和浮点数值的,其中所有的数字均用浮点数值表示.JavaScript采用IEEE 754标准(有兴趣可以浏览网络规范分类下的IEEE 754标准,需要原文件请在留言 ...

随机推荐

  1. app中rem算法

    第一次用vue做APP被rem坑惨了 下面贴出 rem 的算法及使用方法 在自定义js中定义函数 export default { install: function(Vue, options) { ...

  2. [BZOJ 1500]维修数列 [Splay Tree从进阶到住院]

    历尽艰辛终于A掉了这题QwQ 贴COGS评论区几句话=.= 策爷:"splay/块状链表的自虐题.".深刻理解到如果没有M倾向就不要去写这题了.. -Chenyao2333 记得b ...

  3. HTML5使用Canvas来绘制图形

    一.Canvas标签: 1.HTML5<canvas>元素用于图形的绘制,通过脚本(通常是javascript)来完成. 2.<canvas>标签只是图形容器,必须使用脚本来绘 ...

  4. 怎么把系统装进u盘(ultraiso)

    ​首先要下载一个叫ultraiso的软件.可以在百度中搜索此软件下载.下载后安装,安装后打开软件,如图所示.        ​点击左上角的文件选项,在弹出的菜单中,点击打开选项,打开一个你要装进U盘的 ...

  5. 5.npm scripts 使用指南

    简单介绍 scripts里面的 "start": "node app" npm run start 相当于 node app { "name" ...

  6. JBOSS安装配置详细教程

    首先在http://jbossas.jboss.org/downloads/下载相关程序我下载的是 JBoss AS 6.1.0.Final 1.配置jboss环境 1.1用户变量path后面添加 ; ...

  7. NYOJ_23_取石子(一)

    取石子(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 一天,TT在寝室闲着无聊,和同寝的人玩起了取石子游戏,而由于条件有限,他/她们是用旺仔小馒头当作石子.游戏的 ...

  8. LinkStack

    //Node.h template<typename ElemType> struct Node { ElemType data; Node<ElemType> *next; ...

  9. Loadrunner分布式测试

    据经验,每生成一个虚拟用户,需要花费负载生成器大约 2M-3M 的内存空间.通常运行 controller的主机很少用作负载生成器.负载生成器的工作多由其他装有 LR Agent的PC 机来担任.如果 ...

  10. oracle 内连接,外连接

    --内连接  inner join  ...  on  --左外连接 left join ... on  --右外连接  right join ... on 列: select * from stud ...