PHP常用方法封装
其他
2019-05-14 19:09:20
阅读次数: 0
转载自**程序员笔记**
欢迎访问“程序员笔记”
/**
- 引入插件
- $name 插件名称
- $inbo 是否初始化
-
param1,2,参数∗/functionc(name, $inbo=true, $param1=’’, $param2=’’)
{
class=′′.name.‘Chajian’;
path=′′.ROOTPATH.′/include/chajian/′.class.’.php’;
cls=NULL;if(fileexists(path))
{
include_once(
path);if(inbo)$cls = new
class(param1, $param2);
}
return $cls;
}
/**
- 引入class文件
*/
function import($name, $inbo=true)
{
class=′′.name.‘Class’;
path=′′.ROOTPATH.′/include/class/′.class.’.php’;
cls=NULL;if(fileexists(path))
{
include_once(
path);if(inbo)
{
$cls = new $class();
}
}
return $cls;
}
/**
- 判断变量是否为空
- @return boolean
*/
function isempt($str)
{
bool=false;if((str==’’||
str==NULL∣∣empty(str)) && (!is_numeric(
str)))bool=true;
return $bool;
}
/**
- 判断变量是否包含在另一变量里面
- @return boolean
*/
function contain(
str,a)
{
bool=false;if(!isempt(a) && !isempt($str))
{
ad=strpos(str,
a);if(ad>0||!is_bool(
ad))bool=true;
}
return $bool;
}
/**
- 获取请求的头
- @return string/array
*/
function getheader($key=’’)
{
arr=array();if(functionexists(′getallheaders′))arr = getallheaders();
if($key==’’)return
arr;returnarrvalue(arr, $key);
}
/**
- 是否ajax请求
- @return boolean
*/
function isajax()
{
if(strtolower(getheader(‘X-Requested-With’))==‘xmlhttprequest’){
return true;
}else{
return false;
};
}
/**
- 过滤字符串的空格
*/
function trimstr(KaTeX parse error: Double superscript at position 34: …(str_replace(' '̲,'',str));
}
转载自blog.csdn.net/qq_34927434/article/details/90205698