教程08-微擎系统内置所有函数大全
微擎系统内置了很多共函数、HTTP请求函数、文件和数据操作函数。
1. 系统公共函数
系统全局公共函数全部位于 framework/function/global.func.php 文件内。
1.1 istripslashes
istripslashes() - 去掉字符串或是数组中的转义符 (\)
说明
istripslashes($var)
参数
- $var string | array 需要转义的字符串或数组
返回值
去掉字符串或是数组中的转义符 (\),例如:将字符串或数组中的 ’ \“ \ \ 转换为 ’ ” \ 并返回。
示例
echo istripslashes('\r\n\r\n'); // rnrn
print_r(istripslashes(array('\t', '\r', '\n')));Array
([0] => t[1] => r[2] => n
)
1.2 ihtmlspecialchars
ihtmlspecialchars() - 转义字符串或数组中的的HTML,例如将 “php” 转化为 "PHP"
说明
ihtmlspecialchars ($var)
参数
- $var string | array 需要转义的字符串或数组
返回值
将字符串或数组中的HTML代码进行转义并返回。
示例
echo ihtmlspecialchars('<h1>WeiEngine</h1>');//输出如下
<h1>WeiEngine</h1>print_r(ihtmlspecialchars(array('<h1>WeiEngine</h1>', '<h4>WeiXin</h4>')));//输出如下
Array
([0] => <h1>WeiEngine</h1>[1] => <h4>WeiXin</h4>
)
1.3 isetcookie
ihtmlspecialchars() - 转义字符串或数组中的的HTML,例如将 “php” 转化为 "PHP"
说明
ihtmlspecialchars ($var)
参数
- $var string | array 需要转义的字符串或数组
返回值
将字符串或数组中的HTML代码进行转义并返回。
示例
echo ihtmlspecialchars('<h1>WeiEngine</h1>');//输出如下
<h1>WeiEngine</h1>print_r(ihtmlspecialchars(array('<h1>WeiEngine</h1>', '<h4>WeiXin</h4>')));//输出如下
Array
([0] => <h1>WeiEngine</h1>[1] => <h4>WeiXin</h4>
)
1.4 token
token() - 与 checksubmit() 函数配置使用,提交表单时的来源校验码
说明
token()
参数
无
返回值
提交表单时的来源校验码
示例
<form name="form"><input name="token" type="hidden" value="{$_W['token']}" /> // 与 token() 一样<input type="submit" class="btn btn-primary span3" name="submit" value="提交" />
</form>
最佳实践: 系统在入口文件中已经将 token() 的结果赋值给全局变量 $_W[‘token’] ,在需要获取Token的情况下,直接使用 $_W[‘token’] 常量可以增强系统维护性和扩展性。
1.5 random
random() - 获取一个随机数
说明
random($length, $numeric = FALSE)
参数
- $length int 要获取随机数的长度
- $numeric boolean 返回纯数字随机数
返回值
随机字符串
示例
echo random(6); // JUmtIp
echo random(10, true); // 9824464484
1.6 checksubmit
checksubmit() - 验证一下表单提交,必须与 token() 函数一起使用
说明
checksubmit($var = 'submit', $allowget = false)
参数
- $var string 提交表单按钮的名称
- $allowget boolean 是否验证一个get请求
返回值
无
示例
<?phpif (checksubmit('submit')) {exit('表单提交了');
}
?>
<form name="form"><input name="token" type="hidden" value="{$_W['token']}" /> // 与 token() 一样<input type="submit" class="btn btn-primary span3" name="submit" value="提交" />
</form>
1.7 checkcaptcha
checkcaptcha() - 验证用户提交的验证码是否正确
说明
checkcaptcha($code)
参数
- $code string 用户填写的验证码
返回值
验证通过返回true,不通过返回false
示例
if (!checkcaptcha($_GPC['code'])) {message('你输入的验证码不正确, 请重新输入.');
}
1.8 tablename
tablename() - 为了防止表名冲突,微擎所有数据表均有前缀,此函数就是返回加表前缀的表名
说明
tablename($tablename)
参数
- $tablename string 数据表名
返回值
加表前缀的表名
示例
#数据表前缀为 `ims`
echo tablename('account'); // `ims_account`
1.9 array_elements
array_elements() - 从一个数组中取得若干元素
说明
array_elements($keys, $src, $default = FALSE)
参数
- $keys array 需要筛选的键名列表
- $src array 进行筛选的数组
- $default mixed 如果原数组未定义某个键,则使用$default 替换,默认为 false。
返回值
从一个数组中取得的若干元素
示例
$result = array_elements(array('a', 'b', 'c'), array('a' => '1', 'b' => '2', 'd' => '3'), 0);
print_r($result);exit;//输出值
Array ( [a] => 1 [b] => 2 [c] => 0 )
1.10 range_limit
range_limit() - 判断给定参数是否位于区间内或将参数转换为区间内的数
说明
range_limit($num, $downline, $upline, $returnNear = true)
参数
- $number int 待检测的数
- $downline int 区间的最小值
- $upline int 区间的最大值
- $returnNear boolean 为true时小于区间则返回最小值,大于区间则返回最大值,否则返回本身的值
返回值
参考示例
示例
echo range_limit(100, 50, 250, false); // true
echo range_limit(300, 50, 250); // 250
1.11 ijson_encode
ijson_encode() - 获取json格式的字符串函数
说明
ijson_encode($value, $options = 0)
参数
- $value string 需要转化的字符串
- $options int 兼容低版本Php的 options 选项,此值为 JSON_UNESCAPED_UNICODE 时,则不转义中文
返回值
参考示例
示例
echo ijson_encode('hello weiqing'); // \"hello weiqing\"echo ijson_encode(array('title' => '微擎图队123', 'desc' => 'weiqing123'), JSON_UNESCAPED_UNICODE);
// 输出结果 {\"title\":\"微擎图队123\",\"desc\":\"weiqing123\"}
需要注意的是,返回值时会转义引号等字符,如果要传入Js或是当成json对象使用时,请使用 stripslashes(ijson_encode($params, JSON_UNESCAPED_UNICODE))
1.12 iserializer
iserializer() - 获取反序列化后的结果
说明
iserializer($str)
参数
- $str mixed 需要序列化的字符串或数组
返回值
字符串序列化结果
示例
echo iserializer('hello weiqing'); // s:14:"hello weiqing";
var_dump(iserializer(array(1, 2, 3))); // a:3:{i:0;i:1;i:1;i:2;i:2;i:3;;}
1.13 iunserializer
iunserializer() - 获取反序列化后的结果
说明
iunserializer($str)
参数
- $str string 需要反序列化的字符串或数组
返回值
参考示例
示例
print_r(iunserializer('a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}'));
Array
([0] => 1[1] => 2[2] => 3
)
1.14 is_base64
is_base64() - 判断是否为base64加密字符串
说明
is_base64($str)
参数
- $str string 需要检测的数据
返回值
true或者false
示例
var_dump(is_base64('hello')); // false
1.15 is_serialized
is_serialized() - 判断字符串是否序列化
说明
is_serialized($str, $strict = TRUE)
参数
- $str mixed 需要检测的数据
- $strict int 是否为严格模式
返回值
true 或者 false
示例
var_dump(is_serialized('hello')); // false
1.16 wurl
wurl() - 获取web端url地址
说明
wurl($segment, $params = array(), $contain_domain = false)
参数
- $segment string 路由参数
- $params array 附加参数
- $contain_domain boolean 是否包含域名
返回值
Web端URL地址
示例
echo wurl('home/welcome/mc', array('uid' => '100', 'op' => 'foo')); // ./index.php?c=home&a=welcome&do=mc&uid=100&op=foo
1.17 murl
murl() - 获取Mobile端url地址
说明
murl($segment, $params = array(), $noredirect = true, $addhost = false)
参数
- $segment string 路由参数
- $params array 附加参数
- $noredirect boolean 为false时,会自动添加微信后缀 - &wxref=mp.weixin.qq.com#wechat_redirect
- $addhost boolean 为true时,会添加域名
返回值
Mobile端url地址
示例
echo murl('home/welcome/mc', array('uid' => '100', 'op' => 'foo')); // ./index.php?c=home&a=welcome&do=mc&uid=100&op=foo
1.18 pagination
pagination() - 获取分页导航HTML
说明
pagination($total, $pageIndex, $pageSize = 15, $url = '', $context = array('before' => 5, 'after' => 4, 'ajaxcallback' => '', 'callbackfuncname' => '')
参数
- $total int 总记录数
- $pageIndex int 当前页码
- $pageSize int 每页显示条数
- $url string 生成url格式
- $context 附加参数
- before 当前页码前显示几页
- after 当前面码之后显示几页
- ajaxcallback 是否为ajax分页,为真时,会调用 callbackfuncname 传递的函数来获取值
- callbackfuncname
返回值
分页导航HTML
示例
echo pagination(10, 2, 2);
1.19 tomedia
tomedia() - 获取图片附件的URL
说明
tomedia($src, $local_path = false, $is_cahce = false)
参数
- $src string 需要进行转换的路径
- $local_path boolean 是否直接返回本地图片路径
- $is_cache boolean 是否读取缓存
返回值
图片附件的URL
示例
echo tomedia('images/noavatar_middle.gif');
1.20 referer
referer() - 获取引用页的地址
说明
referer($default = '')
参数
- $default string 默认引用页地址
返回值
引用页的地址
示例
$referer = referer();
1.21 strexists
strexists() - 判断字符串是否包含字串
说明
strexists($string, $find)
参数
- $string string 在该字符串中查找
- $find string 需要查找的字串
返回值
true 或者 false
示例
echo strexists('asdfghjk', 'f'); //true
1.22 cutstr
cutstr() - 截取|替换字符串
说明
cutstr($string, $length, $havedot = false, $charset = '')
参数
- $string string 对该字符串截取
- $length int 指定截取的长度
- $havedot boolean 超长字符串结尾是否加省略号 …
- $charset string 指定编码
返回值
截取|替换后的子字符串
示例
echo cutstr('hello-微擎', 5, true); //hello...
1.23 istrlen
istrlen() - 忽略字符编码获取字符串的个数,中文英文皆为1个字符
说明
istrlen($string, $charset = '')
参数
- $string string 指定字符串
- $charset string 指定编码
返回值
字符串的个数
示例
echo istrlen('hello-微擎'); //8
1.24 emotion
emotion() - 获取表情字符串的HTML
说明
emotion($message = '', $size = '24px')
参数
- $message string 表情字符串
- $size string 表情图片大小
返回值
表情字符串的HTML
示例
echo emotion("/::)");
1.25 authcode
authcode() - 字符串加密或解密
说明
authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
参数
- $string string 需要加密或解密的字符串
- $operation string 操作类型’DECODE’或’ENCODE’
- $key string 加密秘钥或解密秘钥
- $expiry int 过期时间
返回值
加密或解密后的字符串
示例
echo authcode('hello-world', 'ENCODE'); //b3ae8oQNH91yF4oshY+8PiBuoSfDSrwoWzYrrmpyIG03c6B3FYFlCA
1.26 sizecount
sizecount() - 将字节大小 (Bytes) 转化为 KB, MB,GB的显示格式
说明
sizecount($size, $unit = false)
参数
- $size int 文件原始大小
- $unit boolean 是否显示单位
返回值
格式化后的大小值
示例
echo sizecount('123456789'); //117.74 MB
1.27 bytecount
bytecount() - 将 KB,MB,GB转化为 字节大小(bytes),与sizecount互为相反
说明
bytecount($str)
参数
- $size string 文件大小单位为 KB,MB,GB
返回值
bit值
示例
echo bytecount('20MB'); //20971520
1.28 array2xml
array2xml() - 获取数组的xml结构
说明
array2xml($arr, $level = 1)
参数
- $arr 需要转换的数组
- $level 节点层级, 1 为 Root
返回
xml结构
示例
var_dump(array2xml(array('TagName' => 'A'))); //<xml><TagName><![CDATA[A]]></TagName></xml>
1.29 xml2array
xml2array() - xml结构转化为数组
说明
xml2array($xml)
参数
- $xml string xml结构的数据
示例
var_dump(xml2array('<xml><TagName><![CDATA[A]]></TagName></xml>'));
array (size=1)'TagName' => string 'A' (length=1)
1.30 scriptname
scriptname() - 获取当前文件的相对路径
说明
scriptname()
参数
无
返回
当前文件的相对路径
示例
echo scriptname(); // /web/test.php
1.31 utf8_bytes
utf8_bytes() - 将unicode编码值转换为utf-8编码字符
说明
utf8_bytes($cp)
参数
- $cp ASCII 码值
返回
utf-8编码字符
示例
echo utf8_bytes('264D');
1.32 isimplexml_load_string
isimplexml_load_string() - 将一个 xml 字符串转化为 xml 对象,重新封装 simplexml_load_string 函数,解决安全问题
说明
isimplexml_load_string($string, $class_name = 'SimpleXMLElement', $options = 0, $ns = '', $is_prefix = false)
参数
- $string string xml字符串
- $class_name string 填入 SimpleXMLElement 此类或是继承于此类的类
- $options int 规定附加的 Libxml 参数,请见 http://php.net/manual/en/libxml.constants.php
- $ns string 规定命名空间前缀或 URI
- $is_prefix boolean 如果 ns 是前缀则为 TRUE,如果 ns 是 URI 则为 FALSE。默认是 FALSE。
示例
$xmlstring= <<<EOF
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1490162242</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[测试内容]]></Content>
<MsgId>1234567890123456</MsgId>
</xml>
EOF;$xml = isimplexml_load_string($xmlstring, 'SimpleXMLElement', LIBXML_NOCDATA);
print_r($xml);exit;//以上输出SimpleXMLElement Object
([ToUserName] => toUser[FromUserName] => fromUser[CreateTime] => 1490162242[MsgType] => text[Content] => 测试内容[MsgId] => 1234567890123456
1.33 aes_decode
aes_decode() - AES解密函数,用于微信数据解密
说明
aes_decode($message, $encodingaeskey = '', $appid = '')
参数
- $message 要解密的数据
- $encodingaeskey 解密的token
- $appid 公众号appid
示例
无
1.34 aes_encode
aes_encode() - AES加密函数,用于微信数据加密
说明
aes_encode($message, $encodingaeskey = '', $appid = '')
参数
- $message 要加密的数据
- $encodingaeskey 加密的token
- $appid 公众号appid
示例
无
1.35 ihtml_entity_decode
ihtml_entity_decode() - 转化html字符串中实体数据为标签数据,修复原函数在utf8编码下被转换成黑块的坑
此函数与 ihtmlspecialchars 对应使用
说明
ihtml_entity_decode($str)
参数
- $str string html字符串
返回
处理后的字符串
示例
echo ihtml_entity_decode('<b>title</b><div>con tent"'</div>')//输出结果
<b>title</b><div>con tent"'</div>
1.36 iarray_change_key_case
iarray_change_key_case() - 获取数组的键为大写或小写
说明
iarray_change_key_case($array, $case = CASE_LOWER)
参数
- $array array 指定数组
- $case int 大写或小写模式
示例
var_dump(iarray_change_key_case(array('action' => 'ze', 'tai' => 'feng'), CASE_UPPER));
//结果:array(2) { ["ACTION"]=> string(2) "ze" ["TAI"]=> string(4) "feng" }
1.37 parse_path
parse_path() - 过滤路径中可能包含的非法字符,建议通过get或是post传递的路径皆用此函数过滤
说明
parse_path($path)
参数
- $path string 字符
返回
正常返回路径,否则返回空
示例
var_dump(parse_path('<?php'));
1.38 strip_gpc
strip_gpc() - 过滤 $_GPC 全局变量中的非法字符
不推荐使用。推荐使用安全操作函数
说明
strip_gpc($values, $type = 'g')
参数
- $values string 要过滤的字符串
- $type string 过滤类型(g,p,c)
示例
无
1.39 to_global_media
to_global_media() - 获取在全局远程附件设置的该图片URL
说明
to_global_media($src)
参数
- $src string 需要进行转换的路径
返回值
在全局远程附件设置的该图片URL
示例
echo to_global_media('images/noavatar_middle.gif');
1.40 iconsole_log
iconsole_log() - 将结果输出到浏览器console中
说明
iconsole_log($data)
参数
- $data mixed 需要输出的数据
示例
...
$notices = $article_table->getList();
iconsole_log($notices);
2. Http请求函数
微擎中http请求函数,依赖于PHP的 CURL 类库。
系统全局公共函数全部位于 framework/function/communication.func.php 文件内。
使用时需要使用 load()->func('communication')
引用
使用示例
附带登录身份请求
一些地址需要用户登录后才可访问,其实就是在请求地址时,附带上用户登录后的 cookie 信息,下面通过示例来讲解。
请求登录地址,提交用户名密码获取登录后的 cookie 信息。
$loginurl = 'https://mp.weixin.qq.com/cgi-bin/bizlogin?action=startlogin';
$response = ihttp_request($loginurl, array('username' => 'xxxxx', //登录的用户名'pwd' => md5('xxxxx'), // 登录的密码'f' => 'json'
), array('CURLOPT_REFERER' => 'https://mp.weixin.qq.com/'
));//登录成功后,把返回的cookie信息存到变量中
$cookie = $response['headers']['Set-Cookie'];$result = json_decode($response['content'], true);
$login_qrcode = ihttp_request('https://mp.weixin.qq.com/' . $result['redirect_url'], array(), array('CURLOPT_COOKIE' => implode(';', $cookie), //再请求别的地址时,附带上登录成功的Cookie信息
));
自定义头部请求
获取微信图片
微信的图片需要要求必须有引用页,程序中无法直接调用,以下代码实现一个具体引用页的请求来获取微信图片
load()->func('communication');
//微信图片
$image = 'https://mmbiz.qlogo.cn/mmbiz_jpg/W0GqhYibias7vXCSLoQicrfiaBJ5bT96UKOMpXDibZdCcJFbCjG30h2Sibxn5HtJp7DZAyOydJ2gttaicMlGfZicrd4yrg/0?wx_fmt=jpeg';
$content = ihttp_request($image, '', array('CURLOPT_REFERER' => 'http://www.qq.com'));
header('Content-Type:image/jpg');
echo $content['content'];
exit();
此实例为获取支付宝的支付地址
支付宝的接口通过301跳转来发送给客户端跳转地址,程序中为了获取此url,故设置请求时不自动跳转
load()->func('communication');
$response = ihttp_request(ALIPAY_GATEWAY . '?' . http_build_query($set, '', '&'), array(), array('CURLOPT_FOLLOWLOCATION' => 0));
return array('url' => $response['headers']['Location']);
此实例为模拟微信请求地址
请求数据为xml格式
load()->func('communication');
$response = ihttp_request($item['apiurl'], $message, array('CURLOPT_HTTPHEADER' => array('Content-Type: text/xml; charset=utf-8')));
return $response['content'];
2.1 ihttp_request
ihttp_request() - 模拟 http 请求
说明
ihttp_request($url, $post = array(), $extra = array(), $timeout = 60)
参数
- $url string 要获取内容的URL,必须是以http或是https开头
- $post array 数组格式,要POST请求的数据,上传文件时,传入 ‘@’ 符号 + 文件路径,比如 ‘file’ ⇒ ‘@/root/1.jpg’
- $extra array 请求附加值,下面会例子中会演示使用方法
- $timeout int 超时时间
返回值
error
可用is_error判断,详见错误处理
success
array
('code' => 200 //http 状态码'status' => OK //http 状态信息'responseline' => HTTP/1.1 200 OK'headers' => array(//返回头部的一些信息//具体功能函数不在这里赘述,可以查看HTTP相关文档)'content' => '<!DOCTYPE html><!--STATUS OK--><html><head>..省略3千字...</body></html>' //网页的HTML内容
)
示例
模拟提交登录表单
load()->func('communication');
$loginurl = 'https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN';
//附加表单数据 用户名和密码
$post = array('username' => $username,'pwd' => $password,
);
$response = ihttp_request($loginurl, $post);
if (is_error($response)) {return false;
}
return true;
上传图片
load()->func('communication');$url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token={$token}&type={$type}";
$data = array('media' => '@' . ATTACHMENT_ROOT . '/images/2017/03/20/e9xhbZsB28HB8bs9bMT228eb85q2bS.jpg',
);
return ihttp_request($url, $data);
2.2 ihttp_get
ihttp_get() - 封装的 GET 请求方法
说明
ihttp_get($url)
参数
- $url string 要获取内容的URL,必须是以http或是https开头
返回值
error
可用is_error判断,详见错误处理
success
array
('code' => 200 //http 状态码'status' => OK //http 状态信息'responseline' => HTTP/1.1 200 OK'headers' => array(//返回头部的一些信息,这里是直接显示百度的返回头部信息//具体功能函数不在这里赘述,可以查看HTTP相关文档'Server' => bfe/1.0.8.18'Date' => Wed, 21 Sep 2016 03:23:54 GMT'Content-Type' => text/html; charset=utf-8'Connection' => close'Vary' => Accept-Encoding'P3P' => CP=" OTI DSP COR IVA OUR IND COM "'Cache-Control' => private'Cxy_all' => baidu+7cf6bc2c9c5ae104a1dad56cb1e2a027'Expires' => Wed, 21 Sep 2016 03:22:58 GMT'X-Powered-By' => HPHP'X-UA-Compatible' => IE=Edge,chrome=1'Strict-Transport-Security' => max-age=604800'BDPAGETYPE' => 1'BDQID' => 0x9f936d6300036048'BDUSERID' => 0// 此处返回服务器给客户端设置的Cookie信息// 下面的例子中会有怎么使用的例子'Set-Cookie' => array('0' => H_PS_PSSID=1437_21014_17944_21127_; path=/; domain=.baidu.com'1' => __bsi=1222377018390; expires=Wed, 21-Sep-16 03:23:59 GMT; domain=www.baidu.com; path=/))'content' => '<!DOCTYPE html><!--STATUS OK--><html><head>..省略3千字...</body></html>' //网页的HTML内容
)
示例
load()->func('communication');
$response = ihttp_get('http://baidu.com');
print_r($response['content']); // 输出百度页面Html
2.3 ihttp_post
ihttp_post() - 封装的POST请求方法
说明
ihttp_post($url, $data)
用法同ihhtp_request
2.4 ihttp_email
ihttp_email() - 发送Email
说明
ihttp_email($to, $subject, $body, $global = false)
参数
- $to string 收件人邮箱
- $subject string 邮件主题
- $body array 数组格式,邮件内容|邮件附件(附件以@开头,可获取到的系统路径)
- $global boolean 是否使用系统邮箱配置信息
返回值
- 发送成功返回 true
- 失败返回错误信息(详见错误处理)
示例
// $body参数可为数组或字符串,注意:数组元素或字符串中,内容以'@'开头的会被解析为邮件附件处理
$attachment1 = '@' . ATTACHMENT_ROOT . '/images/691/2016/08/test1.jpg';
$attachment2 = '@' . ATTACHMENT_ROOT . '/images/691/2016/08/test2.jpg';
$content1 = "内容1";
$content2 = "内容2";
$body = array($content1,$content2,$attachment1,$attachment2
);
load()->func('communication');
$response = ihttp_email('xx@xx.com', '你好,我是微擎工作人员', $body);
3. 文件操作函数
系统文件操作函数全部位于 framework/function/file.func.php 文件内。
注意:该文件内所有函数使用前必须加载文件:
load()->func('file')
3.1 file_write
file_write() - 将数据写入到附件目录中的文件,目录不存在时会自动创建
说明
file_write($filename, $data)
参数
名称 | 类型 | 说明 |
---|---|---|
$filename | string | 文件名称 |
$data | string | 写入数据 |
返回
成功返回 true,否则返回 false
示例
load()->func('file');
file_write('images/201703/23/logo318e8e.png', '图片内容');
//将写入文件实际目录为: /home/wwwroot/weengine/pros/attachment/images/201703/23/logo318e8e.png
3.2 file_read
file_read() - 读取附件目录下的文件
说明
file_read($filename)
参数
名称 | 类型 | 说明 |
---|---|---|
$filename | string | 文件名称 |
返回
文件内容
示例
load()->func('file');
file_read('images/201703/23/logo318e8e.png');
//将读取的文件路径为: /home/wwwroot/weengine/pros/attachment/images/201703/23/logo318e8e.png
3.3 file_move
file_move() - 将文件移动至目标位置,也支持保存上传文件
说明
file_move($filename, $dest)
参数
名称 | 类型 | 说明 |
---|---|---|
$filename | string | 移动的文件 |
$dest | string | 移动的目标位置 |
返回
成功返回 true,否则返回 false
示例
load()->func('file');
file_move(IA_ROOT . '/test.log', IA_ROOT . '/web/test.log');
//保存上传文件
if (!file_move($_FILES['upload']['tmp_name'], ATTACHMENT_ROOT . '/' . $result['path'])) {return error(-1, '保存上传文件失败');
}
3.4 fill_tree
file_tree() - 获取指定目录下所有文件路径
说明
file_tree($path, $include = array())
参数
名称 | 类型 | 说明 |
---|---|---|
$path | string | 要获取文件列表的目录 |
$include | array | 指定只获取哪些子目录 |
返回
文件数组
示例
load()->func('file');
$files = file_tree(IA_ROOT . '/web/common');
print_r($files);Array
([0] => D:/Developing/WeEngine/pro/web/common/bootstrap.sys.inc.php[1] => D:/Developing/WeEngine/pro/web/common/common.func.php[2] => D:/Developing/WeEngine/pro/web/common/frames.inc.php[3] => D:/Developing/WeEngine/pro/web/common/template.func.php[4] => D:/Developing/WeEngine/pro/web/common/tpl.func.php
)
//获取 /web/common 目录和 /web/source 目录
load()->func('file');
$files = file_tree(IA_ROOT . '/web', array('common', 'source'));
print_r($files);
3.5 file_copy
file_copy() - 复制指定目录下所有文件到新目录
说明
file_copy($src, $des, $filter)
参数
名称 | 类型 | 说明 |
---|---|---|
$src | string | 原始文件夹 |
$des | string | 目标文件夹 |
$filter | array | 需要过滤的文件类型 |
返回
无
示例
load()->func('file');
file_copy(IA_ROOT . '/web', IA_ROOT . '/data', array('php'));
3.6 file_upload
file_upload() - 上传文件到附件目录
说明
file_upload($file, $type = 'image', $name = '', $compress = false)
参数
名称 | 类型 | 说明 |
---|---|---|
$file | string | 上传的文件信息 |
$type | string | 文件保存类型 |
$name | string | 保存的文件名,如果为空则自动生成 |
$compress | boolean | 是否压缩 |
返回
错误信息 error 或 array(‘success’ => bool,‘path’ => 保存路径(从附件目录开始的完整相对路径))
示例
load()->func('file');
file_upload($_FILE['test'], 'image', 'test.png');
3.7 file_wechat_upload
file_wechat_upload() - 上传文件到微信服务器
说明
file_wechat_upload($file, $type = 'image', $name = '')
参数
名称 | 类型 | 说明 |
---|---|---|
$file | string | 上传的文件信息 |
$type | string | 文件保存类型 |
$name | string | 保存的文件名,如果为空则自动生成 |
返回
错误信息 error 或 boolean
示例
load()->func('file');
file_wechat_upload($_FILE['test'], 'image', 'test.png');
3.8 file_remote_upload
file_remote_upload() - 上传文件到远程服务器
注意:若上传时,第二个参数设置为false,图片仍然会上传到远程服务器,但使用tomeida()和to_global_media()的时候,所得链接为该站点链接,而非远程链接.故请斟酌使用第二个参数。
说明
file_remote_upload($filename, $auto_delete_local = true)
参数
名称 | 类型 | 说明 |
---|---|---|
$file | string | 上传的文件信息 |
$auto_delete_loca | string | 是否删除本地资源 |
返回
错误信息 error 或 boolean
示例
load()->func('file');
file_remote_upload($_FILE['test']);
3.9 file_random_name
file_random_name() - 获取指定某目录下指定后缀的随机文件名
说明
file_random_name($dir, $ext)
参数
名称 | 类型 | 说明 |
---|---|---|
$dir | string | 目录的绝对路径 |
$ext | string | 文件后缀名 |
返回
随机文件名称
示例
load()->func('file');
file_random_name(IA_ROOT . '/web', 'php'); //wBDINDBBib3bim7nDpNvD7BZF8b6n7.php
3.10 file_delete
file_delete() - 删除文件
说明
file_delete($file)
参数
名称 | 类型 | 说明 |
---|---|---|
$file | string | 需要删除的文件名 |
返回
成功返回true, 否则返回false
示例
load()->func('file');
file_delete('test.php');
3.11 file_remote_delete
file_remote_delete() - 删除远程文件
说明
file_remote_delete($file)
参数
名称 | 类型 | 说明 |
---|---|---|
$file | string | 需要删除的远程文件名 |
返回
成功返回true, 否则返回false
示例
load()->func('file');
file_remote_delete('test.php');
3.12 file_image_thumb
file_image_thumb() - 图像缩略处理
说明
file_image_thumb($srcfile, $desfile = '', $width = 0)
参数
名称 | 类型 | 说明 |
---|---|---|
$srcfile | string | 需要缩略的图像 |
$desfile | string | 缩略完成后的图像 |
$width | int | 缩放宽度 |
返回
成功返回true, 否则返回false
示例
load()->func('file');
file_image_thumb(IA_ROOT . '/test.png', IA_ROOT . '/test2.png', 500);
3.13 file_image_crop
file_image_crop() - 图像裁剪处理
说明
file_image_crop($src, $desfile, $width = 400, $height = 300, $position = 1)
参数
名称 | 类型 | 说明 |
---|---|---|
$src | string | 原图像地址 |
$desfile | string | 新图像地址 |
$width | int | 要裁切的宽度 |
$height | int | 要裁切的高度 |
$position | int | 开始裁切的位置, 按照九宫格1-9指定位置 |
返回
错误信息 error 或者 boolean
示例
load()->func('file');
file_image_crop(IA_ROOT . '/test.png', IA_ROOT . '/test2.png', 50, 50);
3.14 file_lists
file_lists() - 搜索文件
说明
file_lists($filepath, $subdir = 1, $ex = '', $isdir = 0, $md5 = 0, $enforcement = 0)
参数
名称 | 类型 | 说明 |
---|---|---|
$filepat | string | 目录名称 |
$subdir | string | 是否搜索子目录 |
$ext | int | 搜索扩展名称 |
$isdir | int | 是否只搜索目录 |
$md5 | int | 是否生成MD5验证码 |
$enforcement | int | 是否开启强制模式 |
返回
文件信息数组
示例
load()->func('file');
$files = file_lists(IA_ROOT . '/web/common', 1, '.php', 0, 1);
print_r($files);Array
([web/common/bootstrap.sys.inc.php] => 0fda4e584ef1536a4c7e288b807e0e1b[web/common/common.func.php] => 8f9c8510fea317feed355a25c7802d27[web/common/frames.inc.php] => b4c9ae32c77677279ac35dfebcc92257[web/common/template.func.php] => 8dab868691f0fc9ce325b30d44faf378[web/common/tpl.func.php] => b1a172d3290a4cd3456311fae8cf6196
)
3.15 file_remote_attach_fetch
file_remote_attach_fetch() - 获取远程素材
说明
file_remote_attach_fetch($url, $limit = 0, $path = '')
参数
名称 | 类型 | 说明 |
---|---|---|
$url | string | 文件地址 |
$limit | int | 大小限制 |
$path | string | 文件保存路径 |
返回
错误信息error 或 文件path
示例
load()->func('file');
file_remote_attach_fetch('https://s.w7.cc/img/logo-shop.png');
3.16 file_is_image
file_is_image() - 检测是否为图像文件
说明
file_is_image($url)
参数
名称 | 类型 | 说明 |
---|---|---|
$url | string | 文件地址 |
返回
true 或 false
示例
load()->func('file');
file_is_image(IA_ROOT . 'weiqing.jpg');
3.17 mkdirs
mkdirs() - 创建目录树,上级目录可不存在
说明
mkdirs($path)
参数
名称 | 类型 | 说明 |
---|---|---|
$path | string | 需要创建的目录名称 |
返回
true 或 false
示例
load()->func('file');
mkdirs(IA_ROOT . '/web/hello/world/example');
3.18 rmdirs
rmdirs() - 删除目录
说明
rmdirs($path, $clean = false)
参数
名称 | 类型 | 说明 |
---|---|---|
$path | string | 目录位置 |
$clean | boolean | 是否删除整个目录 |
返回
true 或 false
示例
load()->func('file');
rmdirs(IA_ROOT . '/test');
3.19 file_tree_limit
file_tree_limit() - 获取指定目录下一定数量文件的文件路径
说明
file_tree_limit($path, $limit = 0, $acquired_files_count = 0)
参数
名称 | 类型 | 说明 |
---|---|---|
$path | string | 文件夹目录 |
$limit | int | 获取文件数量 |
$acquired_files_count | int | 已获取文件数量 |
返回
文件数组
示例
load()->func('file');
print_r(file_tree_limit(IA_ROOT . '/web'));
3.20 file_dir_exist_image
file_dir_exist_image() - 判断指定目录下是否存在图片
说明
file_dir_exist_image($path)
参数
名称 | 类型 | 说明 |
---|---|---|
$path | string | 文件夹目录 |
返回
true 或者 false
示例
load()->func('file');
var_dump(file_dir_exist_image('./attachement/a.jpg'));
3.21 file_dir_remote_upload
file_dir_remote_upload() - 上传目录下的图片到远程服务器并删除本地图片
说明
file_dir_remote_upload($dir_path, $limit = 200)
参数
名称 | 类型 | 说明 |
---|---|---|
$dir_path | string | 目录路径 |
$limit | int | 上传数量限制 |
返回
true 或者 错误信息 error
示例
load()->func('file');
var_dump(file_dir_remote_upload('./attachement/images/20'));
3.22 file_allowed_media
file_allowed_media() - 获取系统支持的素材类型
说明
file_allowed_media($type)
参数
名称 | 类型 | 说明 |
---|---|---|
$type | string | 图片和音视频 |
返回
系统支持的素材类型数组
示例
load()->func('file');
var_dump(file_allowed_media('image'));
3.23 file_media_content_type
file_media_content_type() - 获取素材类型及扩展名
说明
file_media_content_type($url)
参数
名称 | 类型 | 说明 |
---|---|---|
$url | string | 素材地址 |
返回
素材类型及扩展名数组 或 boolean值
示例
load()->func('file');
var_dump(file_media_content_type('./attachement/a.jpg'));
3.24 file_is_uni_attach
file_is_uni_attach() - 是否平台账号素材
说明
file_is_uni_attach($file)
参数
名称 | 类型 | 说明 |
---|---|---|
$file | string | 素材地址 |
返回
true 或者 false
示例
load()->func('file');
var_dump(file_is_uni_attach('./attachement/a.jpg'));
3.25 file_check_uni_space
file_check_uni_space() - 验证是否超出附件空间限制
说明
file_check_uni_space($file)
参数
名称 | 类型 | 说明 |
---|---|---|
$file | string | 素材文件 |
返回
错误信息 error 或者 boolean值
示例
load()->func('file');
var_dump(file_check_uni_space('./attachement/a.jpg'));
4. 数据库维护函数
4.1 db_table_schema
db_table_schema() - 获得某个数据表的结构
说明
db_table_schema($db, $tablename = '')
参数
名称 | 类型 | 说明 |
---|---|---|
$db | object | 数据库操作对象 |
$tablename | string | 表名 |
示例
$scahema = db_table_schema(pdo(), 'article_category');
print_r($scahema);Array ('tablename' => ims_article_category, //表名'charset' => utf8_general_ci, //字符集'engine' => MyISAM, //存储引擎'increment' => 1, //下一个自增值'fields' => Array ( //字段结构'id' => Array ('name' => id, //字段id'type' => int, //字段类型'length' => 10, //字段长度'null' =>'signed' =>'increment' => 1 //自增1),'title' => Array ('name' => title, 'type' => varchar, 'length' => 30, 'null' =>'signed' => 1,'increment' =>),'displayorder' => Array ('name' => displayorder, 'type' => tinyint, 'length' => 3, 'null' =>'signed' =>'increment' =>),'type' => Array ('name' => type, 'type' => varchar, 'length' => 15, 'null' =>'signed' => 1, 'increment' =>)),'indexes' => Array ( 'PRIMARY' => Array ('name' => PRIMARY,'type' => primary,'fields' => Array ( '0' => id ) //主键索引id),'type' => Array ('name' => type,'type' => index,'fields' => Array ( '0' => type ) //唯一索引type))
)
4.2 db_table_serialize
db_table_serialize() - 获得数据表的序列化结构
说明
db_table_serialize($db, $dbname)
参数
名称 | 类型 | 说明 |
---|---|---|
$db | object | 数据库操作对象 |
$dbname | string | 数据库名 |
示例
$scahema = db_table_serialize();
var_dump($scahema);
4.3 db_table_create_sql
db_table_create_sql() - 获得数据表的序列化结构
说明
db_table_create_sql($schema)
参数
名称 | 类型 | 说明 |
---|---|---|
$schema | array | 创建数据表所需要各项参数 |
示例
$id = array('type' => 'id', 'default' => 12, 'increment' => 'AUTO_INCREMENT');
$sex = array('type' => 'sex', 'default' => 1);
$age = array('type' => 'age', 'default' => 0);
$index = array('fields' => array('id'), 'type' => 'primary');echo db_table_create_sql(array('tablename' => 'zefeng', 'fields' => array($id, $sex, $age), 'indexes' => array($index), 'engine' => 'InnoDB', 'charset' => 'utf8'));//CREATE TABLE IF NOT EXISTS `zefeng` ( `` id unsigned NOT NULL DEFAULT '12' AUTO_INCREMENT, `` sex unsigned NOT NULL DEFAULT '1', `` age unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4.4 db_schema_compare
db_schema_compare() - 两个表进行比较
说明
db_schema_compare($table1, $table2)
参数
名称 | 类型 | 说明 |
---|---|---|
$table1 | array | 数组形式的表一各项参数 |
$table2 | array | 数组形式的表二各项参数 |
示例
$id = array('type' => 'id', 'default' => 12, 'increment' => 'AUTO_INCREMENT');
$sex = array('type' => 'sex', 'default' => 1);
$age = array('type' => 'age', 'default' => 0);
$index = array('fields' => array('id'), 'type' => 'primary');
$table1 = array('tablename' => 'zefeng', 'fields' => array($id, $sex, $age), 'indexes' => array($index), 'engine' => 'InnoDB', 'charset' => 'utf8');
$id = array('type' => 'id', 'default' => 12, 'increment' => 'AUTO_INCREMENT');
$name = array('type' => 'name', 'default' => 11);
$ages = array('type' => 'ages', 'default' => 0);
$index = array('fields' => array('name'), 'type' => 'index');
$table2 = array('tablename' => 'zefeng', 'fields' => array($id, $name, $ages), 'indexes' => array($index), 'engine' => 'InnoDB', 'charset' => 'utf8');
var_dump(db_schema_compare($table1, $table2));
4.5 db_table_fix_sql
db_table_fix_sql() - 创建修复两张差异表
说明
db_table_fix_sql($schema1, $schema2, $strict = false)
参数
名称 | 类型 | 说明 |
---|---|---|
$schema1 | string | 表结构 需要修复的表 |
$schema2 | string | 表结构 基准表 |
$strict | boolean | 使用严格模式, 严格模式将会把表2完全变成表1的结构, 否则将只处理表2种大于表1的内容(多出的字段和索引) |
示例
$id = array('type' => 'id', 'default' => 12, 'increment' => 'AUTO_INCREMENT');
$sex = array('type' => 'sex', 'default' => 1);
$age = array('type' => 'age', 'default' => 0);
$index = array('fields' => array('id'), 'type' => 'primary');
$table1 = array('tablename' => 'zefeng', 'fields' => array($id, $sex, $age), 'indexes' => array($index), 'engine' => 'InnoDB', 'charset' => 'utf8');
$id = array('type' => 'id', 'default' => 12, 'increment' => 'AUTO_INCREMENT');
$name = array('type' => 'name', 'default' => 11);
$age = array('type' => 'ages', 'default' => 0);
$index = array('fields' => array('name'), 'type' => 'index');
$table2 = array('tablename' => 'zefeng', 'fields' => array($id, $name, $age), 'indexes' => array($index), 'engine' => 'InnoDB', 'charset' => 'utf8');
var_dump(db_table_fix_sql($table1, $table2));array (size=3)0 => string 'ALTER TABLE `zefeng` CHANGE `` `` name unsigned NOT NULL DEFAULT '11'' (length=69)1 => string 'ALTER TABLE `zefeng` CHANGE `` `` ages unsigned NOT NULL DEFAULT '0'' (length=68)2 => string 'ALTER TABLE `zefeng` DROP PRIMARY KEY , ADD INDEX `` (`name`)' (length=63)
4.6 _db_build_index_sql
_db_build_index_sql() - 为数据表创建索引
说明
_db_build_index_sql($index)
参数
名称 | 类型 | 说明 |
---|---|---|
$index | array | 索引数组 |
示例
$scahema = _db_build_index_sql(array('fields' => array('name', 'age'), 'type' => 'index'));
echo $scahema; //' INDEX `` (`name`,`age`)'
4.7 _db_build_field_sql
_db_build_field_sql() - 创建一个完整字段
说明
_db_build_field_sql($field)
参数
名称 | 类型 | 说明 |
---|---|---|
$field | array | 字段数组 |
示例
$scahema = _db_build_field_sql(array('type' => 'name', 'default' => 12, 'increment' => 'AUTO_INCREMENT'));
echo $scahema; //'name unsigned NOT NULL DEFAULT '12' AUTO_INCREMENT' (length=50)
4.8 db_table_schemas
db_table_schemas() - 获取表的结构
说明
db_table_schemas($table)
参数
名称 | 类型 | 说明 |
---|---|---|
$table | string | 表名 |
示例
$scahema = db_table_schemas('ims_account');
var_dump($scahema);CREATE TABLE `ims_account` (`acid` int(10) unsigned NOT NULL AUTO_INCREMENT,`uniacid` int(10) unsigned NOT NULL,`hash` varchar(8) NOT NULL,`type` tinyint(3) unsigned NOT NULL,`isconnect` tinyint(4) NOT NULL,`isdeleted` tinyint(3) unsigned NOT NULL,PRIMARY KEY (`acid`),KEY `idx_uniacid` (`uniacid`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
4.9 db_table_insert_sql
db_table_insert_sql() - 获取某个表的insert语句
说明
db_table_insert_sql($tablename, $start, $size)
参数
名称 | 类型 | 说明 |
---|---|---|
$tablename | string | 表名 |
$start | int | 开始 |
$size | int | 大小 |
示例
$scahema = db_table_insert_sql('ims_core_cache', 1, 3);
var_dump($scahema);array (size=2)'data' => string 'INSERT INTO ims_core_cache VALUES
('system_frame','a:5:{s:8:\"platform\";a:3:{i:0;a:2:{s:5:\"title\";s:12:\"基本功能\";s:5:\"items\";a:9:{i:0;a:5:{s:2:\"id\";s:1:\"3\";s:5:\"title\";s:12:\"文字回复\";s:3:\"url\";s:38:\"./index.php?c=platform&a=reply&m=basic\";s:15:\"permission_name\";s:20:\"platform_reply_basic\";s:6:\"append\";a:2:{s:5:\"title\";s:26:\"<i class=\"fa fa-plus\"></i>\";s:3:\"url\";s:46:\"./index.php?c=platform&a=reply&do=post&m=basic\";}}i:1;a:5:{s:2:\"id\";s:1:\"4\";s:5:\"title\";s:'... (length=13798)'result' =>array (size=3)0 =>array (size=2)'key' => string 'system_frame' (length=12)'value' => string 'a:5:{s:8:"platform";a:3:{i:0;a:2:{s:5:"title";s:12:"基本功能";s:5:"items";a:9:{i:0;a:5:{s:2:"id";s:1:"3";s:5:"title";s:12:"文字回复";s:3:"url";s:38:"./index.php?c=platform&a=reply&m=basic";s:15:"permission_name";s:20:"platform_reply_basic";s:6:"append";a:2:{s:5:"title";s:26:"<i class="fa fa-plus"></i>";s:3:"url";s:46:"./index.php?c=platform&a=reply&do=post&m=basic";}}i:1;a:5:{s:2:"id";s:1:"4";s:5:"title";s:12:"图文回复";s:3:"url";s:37:"./index.php?c=platform&a=reply&m=news";s:15:"permission_name'... (length=9576)1 =>array (size=2)'key' => string 'userbasefields' (length=14)'value' => string 'a:44:{s:7:"uniacid";s:17:"同一公众号id";s:7:"groupid";s:8:"分组id";s:7:"credit1";s:6:"积分";s:7:"credit2";s:6:"余额";s:7:"credit3";s:19:"预留积分类型3";s:7:"credit4";s:19:"预留积分类型4";s:7:"credit5";s:19:"预留积分类型5";s:7:"credit6";s:19:"预留积分类型6";s:10:"createtime";s:12:"加入时间";s:6:"mobile";s:12:"手机号码";s:5:"email";s:12:"电子邮箱";s:8:"realname";s:12:"真实姓名";s:8:"nickname";s:6:"昵称";s:6:"avatar";s:6:"头像";s:2:"qq";s:5:"QQ号";s:6:"ge'... (length=1383)2 =>array (size=2)'key' => string 'usersfields' (length=11)'value' => string 'a:45:{s:8:"realname";s:12:"真实姓名";s:8:"nickname";s:6:"昵称";s:6:"avatar";s:6:"头像";s:2:"qq";s:5:"QQ号";s:6:"mobile";s:12:"手机号码";s:3:"vip";s:9:"VIP级别";s:6:"gender";s:6:"性别";s:9:"birthyear";s:12:"出生生日";s:13:"constellation";s:6:"星座";s:6:"zodiac";s:6:"生肖";s:9:"telephone";s:12:"固定电话";s:6:"idcard";s:12:"证件号码";s:9:"studentid";s:6:"学号";s:5:"grade";s:6:"班级";s:7:"address";s:12:"邮寄地址";s:7:"zipcode";s:6:"邮编";s:11:"nationality";s:6:"国籍"'... (length=1440)
5. Web端公共函数
web端公共函数,开发者在管理员后台开发中可直接使用。
5.1 url
url() - 创建一个URL
说明
url($segment, $params = array())
参数
名称 | 类型 | 说明 |
---|---|---|
$segment | string |
路由信息字符串,eg:{$controller}/{$action}[/{$do}]
|
$params | array | queryString 参数 |
返回值
string url地址,形如:
./index.php?c=*&a=*&do=*&…
5.2 message
message() - 页面执行中断并跳转到消息提示页面。
说明
message($msg, $redirect = '', $type = '')
参数
名称 | 类型 | 说明 |
---|---|---|
$msg | string | 提示的消息内容 |
$redirect | string | 跳转地址,可缺省 |
$type | string | 提示类型,取值不同,消息页面呈现不同效果。 |
说明
- $redirect
- null 缺省,不进行跳转。
- refresh 显示 message 页面后,重新跳转到当前执行的页面
- referer 显示 message 页面后,回退到当前执行页面的上一页面
- $url string 跳转到指定页面
- $type
- success 成功
- error 错误
- info 提示(灯泡)
- warning 警告(叹号)
- sql
- ajax 不跳转到 message 页面,但是页面输出 json
取值 ‘ajax’ 时,eg:
// 不跳转到 message 页面,但是页面输出 json_encode($var)
$var = array('message' => $msg;'redirect' => $redirect; 'type' => $type;
);
return json_encode($var);
5.3 checklogin
checklogin() - 验证操作用户是否已登录
说明
checklogin()
返回值
- boolean 验证结果为已登录,返回 true
或者
- void 中断文件执行, 提示用户未登录,跳转到【用户登录】界面
5.4 template
template() - 展示特定模板内容
说明
mixed function template(string $filename, int $flag = TEMPLATE_DISPLAY)
参数
名称 | 类型 | 说明 |
---|---|---|
$filename | string | 模板名称,格式为: ‘模板文件夹/模板名称无后缀’,如: ‘common/header’ |
$flag | int | 模板展示方式 |
返回值
调用PHP模板文件
说明
- $flag
- EMPLATE_DISPLAY 导入全局变量,渲染并直接展示模板内容(默认值)
- TEMPLATE_FETCH 导入全局变量,渲染模板内容,但不展示模板内容,而是将其作为返回值获取。 可用于静态化页面。
- TEMPLATE_INCLUDEPATH 不导入全局变量,也不渲染模板内容,只是将编译后的模板文件路径返回,返回的模板编译路径可以直接使用 include 嵌入至当前上下文。
示例
以下三种调用方式效果相同
// 直接展示模板
template('common/template');// 获取模板渲染出的内容
$content = template('common/template', TEMPLATE_FETCH);
// 输出渲染的内容
echo $content;// 嵌入模板编译路径
include template('common/template', TEMPLATE_INCLUDEPATH);
6. App端公共函数
app端公共函数,开发者在手机端开发中可直接使用。
6.1 url
url() - 创建一个URL
说明
url($segment, $params = array(), $noredirect = false)
参数
名称 | 类型 | 说明 |
---|---|---|
$segment | string |
路由信息字符串,eg:$controller/$action[/$do]
|
$params | array | queryString 参数 |
$noredirect | bool | 是否追加微信URl后缀 |
微信默认要求 mobile 端地址自动附加 ‘&wxref=mp.weixin.qq.com#wechat_redirect’ 信息
返回值
./index.php?i={$uniacid}&c=*&a=*&do=*&…
或
./index.php?i=181&c=ctrl&a=act&do=do&id=1&size=10&wxref=mp.weixin.qq.com#wechat_redirect
6.2 checkauth
url() - 创建一个URL
说明
url($segment, $params = array(), $noredirect = false)
参数
名称 | 类型 | 说明 |
---|---|---|
$segment | string |
路由信息字符串,eg:$controller/$action[/$do]
|
$params | array | queryString 参数 |
$noredirect | bool | 是否追加微信URl后缀 |
微信默认要求 mobile 端地址自动附加 ‘&wxref=mp.weixin.qq.com#wechat_redirect’ 信息
返回值
./index.php?i={$uniacid}&c=*&a=*&do=*&…
或
./index.php?i=181&c=ctrl&a=act&do=do&id=1&size=10&wxref=mp.weixin.qq.com#wechat_redirect
6.3 message
message() - 页面执行中断并跳转到消息提示页面。
说明
message($msg, $redirect = '', $type = '')
6.4 template
template() - 调用模板
说明
template($filename)
6.5 register_jssdk
register_jssdk() - 可以在 app 端使用, 在不使用系统 {template ‘common/header’} 及 {template ‘common/footer’} 的页面中, 在头部先于任何 js 文件引入, 调用此方法, 即可注册 wx 对象, 供开发者使用 jssdk
内部实现了 借用 js 分享 (如果设置了借用)
说明
register_jssdk($debug = false)
参数
名称 | 类型 | 说明 |
---|---|---|
$debug | boolean | 是否启用调试 |
返回值
html 代码
7. 安全操作函数
safe_gpc_int() - 转换一个安全数字
说明
safe_gpc_int($value, $default = 0)
参数
名称 | 类型 | 说明 |
---|---|---|
$value | string | 要转换的数字 |
$default | int | $value为空时,返回的默认值 |
返回值
一个安全数字
示例
echo safe_gpc_int('56');
safe_gpc_belong() - 检测某个值是否在某一数组中
说明
safe_gpc_belong($value, $allow = array(), $default = '')
参数
名称 | 类型 | 说明 |
---|---|---|
$value | string或array | 要检测的值 |
$allow | array | 要检测的数组 |
$default | string | 如果value不在allow中,返回的默认值 |
返回值
参考示例
示例
echo safe_gpc_belong(56, array(12, 34, 56)); // 56
safe_gpc_string() - 转换一个安全字符串
说明
safe_gpc_string($value, $default = '')
参数
名称 | 类型 | 说明 |
---|---|---|
$value | string | 需要进行转换的字符串 |
$default | string | $value为空时,返回的默认值 |
返回值
一个安全字符串
示例
echo safe_gpc_string('images/noavatar_middle.gif');
safe_gpc_path() - 转换一个安全路径
说明
safe_gpc_path($value, $default = '')
参数
名称 | 类型 | 说明 |
---|---|---|
$value | string | 需要进行转换的路径 |
$default | string | 返回的默认值 |
返回值
一个安全路径
示例
echo safe_gpc_path('./images/noavatar_middle.gif');
safe_gpc_array() - 转换一个安全的字符串型数组
说明
safe_gpc_array($value, $default = array())
参数
名称 | 类型 | 说明 |
---|---|---|
$value | array | 需要进行转换的字符串型数组 |
$default | array | 默认返回值 |
返回值
一个安全的字符串型数组
示例
print_r(safe_gpc_array(array('a', 'b' , 'c')));
safe_gpc_boolean() - 转换一个安全的布尔值
说明
safe_gpc_boolean($value)
参数
名称 | 类型 | 说明 |
---|---|---|
$value | string | 需要进行转换的字符串 |
返回值
布尔值
示例
var_dump(safe_gpc_boolean('images/noavatar_middle.gif')); // bool(true)
safe_gpc_html() - 转换一个安全HTML数据
说明
safe_gpc_html($value, $default = '')
参数
名称 | 类型 | 说明 |
---|---|---|
$value | string | 需要进行转换的HTML数据 |
$default | string | 默认返回值 |
返回值
一个安全HTML数据
示例
var_dump(safe_gpc_html('<div>html data.</div>')); //string(21) "<div>html data.</div>"
safe_gpc_url() - 转换一个安全URL
说明
safe_gpc_url($value, $strict_domain = true, $default = '')
参数
名称 | 类型 | 说明 |
---|---|---|
$value | string | 需要进行转换的URL |
$strict_domain | boolean | 是否严格限制只能为当前域下的URL |
$default | string | 默认返回值 |
返回值
一个安全URL
示例
echo safe_gpc_url('http://prox.we7.com/images/noavatar_middle.gif');
safe_remove_xss() - 去掉可能造成xss攻击的字符
说明
safe_remove_xss($value)
参数
名称 | 类型 | 说明 |
---|---|---|
$value | string | 需处理的字符串 |
返回值
相对安全的字符串
示例
echo safe_remove_xss('<script>alert(1)</script>'); // <sc<x>ript>alert(1)</sc<x>ript>
教程08-微擎系统内置所有函数大全相关推荐
- 微擎系统内置的所有函数大全,一共5435个,可以当作微擎开发函数手册来查看(下篇)
基于官方微擎v2.7.5版本的开放源代码,再结合微擎开发文档,收集和整理了5435个函数,包含了整个微擎系统的所有函数. 大家可以通过英文函数名称,大概推测出那个函数的用途,在做微擎开发的时候,用电脑 ...
- 微信订阅通知开发 (小白教程)微擎
微擎复制可用 微擎访问绕过登陆校验请查看 https://blog.csdn.net/fuchto/article/details/118190252 文中 微擎 WeAccount::create( ...
- mysql内置时间函数大全_MySQL 的时间函数 大全
MySQL 的时间函数 大全 2014年02月14号 发表于:评论 (1) 热度:1109 一.MySQL获得当前日期时间函数 1.1 获得当前日期+ 时间(date + time)函数:now ...
- 9.9元进群项目源码/付费进群源码含搭建教程以及微擎工具
9.9元进群项目源码/付费进群源码 功能简介: 源码的功能其实就是一个单独的页面,在上面你可以在后台自定义你的内容,底部会显示9.9(可自定义)入群.当然也可以加价,也可以换别的,不只是进群. 还可以 ...
- PHP -----微擎内置方法生成二维码和下载二维码
1.新建一个类文件code.php,主要用于处理二维码的方法: 在页面的 顶部引用: load()->library('qrcode'); class code{//方法写在这 } 2.生成二维 ...
- Oracle 内置sql函数大全
F.1字符函数--返回字符值 这些函数全都接收的是字符族类型的参数(CHR除外)并且返回字符值.除了特别说明的之外,这些函数大部分返回VARCHAR2类型的数值.字符函数的返回类型所受的限制和基本数据 ...
- 如何评价微擎?怎么看待微擎模块应用?
你的疑问:微擎是干嘛用的?有使用教程吗? 专家解答:微擎是一套PHP + MySql的开源系统,主要应用于微信公众号和小程序的托管,有活跃的第三方应用开发者.微擎官方网站有安装使用教程,如果是购买了微 ...
- 微擎公众号如何配置微信支付?
转载自资源寺-微擎公众号如何配置微信支付? 本篇教程针对微擎对接好认证服务号后,配置微信支付的教程 多应用模块都含有微信支付等功能,比如购买会员.购买商品等,有些模块在其本身的参数设置上就需要设置微信 ...
- 微擎小程序怎么配置服务器域名,随便撸源码源码微擎小程序通用配置图文教程,教会你怎么配置微擎小程序!...
最近很多网友都在问站长微擎小程序如何配置使用,微擎小程序配置 查看更多关于 微擎小程序配置 的文章 主要分几类,之前已经写过人人商城小程序的配置教程了,大家反响非常好,简单就学会了配置人人商城小程序. ...
最新文章
- vim win装_VIM的代码补全工具YouCompleteMe在Windows上的安装攻略
- Linux下Nagios的安装与配置
- python读数据-python中如何读入数据
- jquery 判断元素内容是否为空
- linux eclipse go插件,Eclipse的Go插件(goclipse)
- Delphi中运行时改变panel的位置及大小
- 计算1~n之间所有奇数之和_所有奇数长度子数组的和
- android手机设置时间设置,如何设置电信定制手机日期与时间
- oracle查看锁表进程,杀掉锁表进程
- Forrester报告拆解:强劲冲击第一梯队后,京东智联云站稳云市场新格局
- 导入工程时出现错误:Invalid project description http://berdy.iteye.com/blog/1115279...
- 练习题︱ python 协同过滤ALS模型实现:商品推荐 + 用户人群放大
- EtherCAT总线伺服速度控制功能块(H5U PLC)
- 智能优化算法——篇1
- 艺工交叉——观《达芬奇的人生密码》有感
- Android高德地图marker和InfoWindow的使用
- SV中的浅拷贝和深拷贝
- ubuntu下的opencv下载编译安装
- Harray Potter and the Sorcerer's Stone
- 物联网流量卡怎么查流量_物联网卡流量查询(QueryCardFlowInfo)---JAVA