常用
header( 'Content-Type:text/html;charset=utf-8 ');
global $_G;
$uniqid = uniqid();
$this->Current();同类方法调用
$pageSize = getgpc('pageSize');
$pageSize = isset($_GET['pageSize']) ? $_GET['pageSize'] : 10;
$pageSize = $pageSize ? $pageSize : 10;
常量:
define('ROOT_PATH', dirname(__FILE__).'/../../');
$path=ROOT_PATH.'./config/config_global.php';
echo $path;
define('ROOT_PATH', dirname(__FILE__));
define("WWWROOT",str_ireplace(str_replace("/","\",$_SERVER['PHP_SELF']),'',__FILE__)."\");
define("APPROOT",$_SERVER['DOCUMENT_ROOT']);
字符串格式数组拼接:
$column = is_array($columns) ? implode(', ', $columns) : $columns;
$sql = sprintf("SELECT %s FROM %s WHERE userid=%s",$column,"%t",$uid);
setcookie("aaa",$aaaa,time()+3600*12,"/");
setcookie("aa", $user, expire, path, domain);
// 设置 cookie 过期时间为过去 1 小时
setcookie("username", "", time()-3600);
setcookie("username","OKadmin",time()-3600);
setcookie("username","OKadmin",0); //浏览器关闭 是自动失效
setcookie("username");
SQL字段特殊处理办法:单引号?没看懂这个符号.
$options = array(
'fields' => 'id,`desc`,createTime',}
`desc` `group`
日期时间常用
$starttime = $starttime ? date('Y-m-d 00:00:00',strtotime($starttime)) : date('Y-m-d 00:00:00',time());
$endtime = $endtime ? date('Y-m-d 23:59:59',strtotime($endtime)) : date('Y-m-d 23:59:59',time());
$condition['where'] .= " AND createTime BETWEEN '{$starttime}' AND '{$endtime}'";
HTTP
private function httpGet($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 500); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_URL, $url); $res = curl_exec($curl); curl_close($curl); return $res; }
Redis
//$data = self::m('#demo_session')->login($request); //$data = self::m('#demo_session')->setAccessToken('888'); //$data = self::m('#demo_session')->getAccessToken('5b1ba608b4b59'); //$data = self::m('#demo_session')->rmAccessToken('5b1ba608b4b59'); //$data = self::m('#demo_session')->CurrentModeName(); public function setAccessToken($uid) { if($uid==NULL){return NULL;} $uniqid = uniqid(); $cachename = 'root#demo#Token#'.$uniqid; if(C::memory()->enable && $data = memory('set', $cachename , $uid , 60)) { return $uniqid; } return NULL; } public function getAccessToken($uniqid) { if($uniqid==NULL){return NULL;} $cachename = 'root#demo#Token#'.$uniqid; if(C::memory()->enable && $uid = memory('get', $cachename)) { return $uid; } return NULL; } public function rmAccessToken($uniqid) { if($uniqid==NULL){return NULL;} $cachename = 'root#demo#Token#'.$uniqid; if(C::memory()->enable && $data = memory('rm', $cachename)) { return $data; } return NULL; } public function CurrentModeName() { $data = 'root#demo#Token#';return $data; }
PHP内置函数
PHP number_format()
array_column() 返回输入数组中某个单一列的值。
echo intval("0x1a", 0), " "; // 使用16进制。 结果 "26" echo intval("057", 0), " "; // 使用8进制。 结果 "47" echo intval("57")," "; // 使用10进制。结果57 echo intval("42", 0), " "; // 结果 "42"
PHP向数组添加新元素的两种方法
$a = array(1); $a[] = 3; array_push($a,44); echo "<pre>"; print_r($a); exit;
json
var obj = JSON.stringify({ a: ('888'), b: ('123'), now: new Date().getTime() });
需要使用JSON.stringify,它将js的数据类型转为json格式的字符串: '{"a":12,"b":34,"now":1403525674676}'
如果不用JSON.stringify,那POST消息体是普通的字符串: 'a=12&b=34&now=1403525674676'
以下写法并不能达到POST JSON数据包的效果,这是标准的POST格式。
console.log(data);
alert(data.text);
var jsonStr = '{"name":"zhangsan","age":23,"email":"chentging@aliyun.com"}';console.log(jsonStr);
var json = eval ("(" + jsonStr + ")");console.log(json);
//var obj = jQuery.parseJSON(data);console.log(obj);
//var obj = JSON.parse(data);
<?php $people = array("Peter", "Joe", "Glenn", "Cleveland"); if(in_array("Glenn",$people)){ echo "Match found"; }else{ echo "Match not found"; } ?>
LayUI 常用注意事项
//var $ = layui.jquery; var $ = layui.$;