• php


    header设置:
    header("Pragma:no-cache");//不缓存页面
    header( 'Content-type: text/html;charset=utf-8' );//设置页面编码
    header('Content-type: application/json');//json
    header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"' ); //个人隐私保护
    header("Location: {$url}");//重定向


    错误设置:
    error_reporting(0);//禁用错误报告 
    error_reporting(E_ALL ^ E_NOTICE);//显示除去 E_NOTICE 之外的所有错误信息 
    error_reporting(E_ALL^E_WARNING^E_NOTICE);//显示除去E_WARNING E_NOTICE 之外的所有错误信息 
    error_reporting(E_ERROR | E_WARNING | E_PARSE);//显示运行时错误,与error_reporting(E_ALL ^ E_NOTICE);效果相同。
    error_reporting(E_ALL);//显示所有错误


    其他设置:
    set_time_limit($seconds);//设置脚本执行时间,0不限制
    date_default_timezone_set('Asia/Shanghai');//设定时区


    //匹配只有中文
    preg_match("/^[x{4e00}-x{9fa5}]+$/u",$name) 
    preg_match('/([x80-xFE][x40-x7Ex80-xFE])+/', $name)
    preg_match("/[".chr(0xa1)."-".chr(0xff)."]/", $name)


    //动态实例化类和方法
    $modules = 'commonmodules\'.$value['modules'];
    $modulesObj = new $modules;
    $res[$key] = $modulesObj->{$value['function']}(['series_id' => $series_id]);


    命令行:
    php -lf test.php //检查语法错误
    php -i //phpinfo


    函数相关:
    iconv("GB2312", "UTF-8",$str); //中文转英文
    /**
     * [date 转换成 unix时间戳]
     * @param  string $date [description]
     * @return [type]       [description]
     */
    if ( ! function_exists('date_to_unixtime'))
    {
        function date_to_unixtime($date = "2038-01-19 11:14:07") {
            $datetime = new DateTime($date);
            return $datetime->format('U');//输出2147483647
        } 
    }
    /**
     * [unix时间戳 转换成 date]
     * @param  string  $unixtime [description]
     * @param  integer $timezone [description]
     * @return [type]            [description]
     */
    if ( ! function_exists('unixtime_to_date'))
    {
        function unixtime_to_date($unixtime = '2147483647', $format ="Y-m-d" ,$timezone = 8) {
            $time = $unixtime + $timezone * 3600;
            $datetime = new DateTime("@$time"); //DateTime类的bug,加入@可以将Unix时间戳作为参数传入DateTime构造函数
            return $datetime->format($format);//输出2038-01-19 11:14:07
        }
    }
  • 相关阅读:
    linux创建用户
    Java理解笔记------杂项
    java高效并发
    GPG备份秘钥
    (二)数据同步利器syncthing
    (一)安装samba
    (序)利旧打造私有云
    mysql的docker化安装
    (八)netty的SSL renegotiation攻击漏洞
    (七)json序列化
  • 原文地址:https://www.cnblogs.com/fonyer/p/8871451.html
Copyright © 2020-2023  润新知