PHP检测是否是手机访问 不指定

jed , 2018-3-14 10:02 , 代码编程 , 评论(0) , 阅读(1730) , Via 本站原创

/**
* 检测是否是手机访问
*/
function is_mobile()
{
    $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
    $useragent_commentsblock = preg_match('|\(.*?\)|', $useragent, $matches) > 0 ? $matches[0] : '';
    function _is_mobile($substrs, $text)
    {
        foreach ($substrs as $substr)
            if (false !== strpos($text, $substr)) {
                return true;
            }
        return false;
    }

    $mobile_os_list = array('Google Wireless Transcoder', 'Windows CE', 'WindowsCE', 'Symbian', 'Android', 'armv6l', 'armv5', 'Mobile', 'CentOS', 'mowser', 'AvantGo', 'Opera Mobi', 'J2ME/MIDP', 'Smartphone', 'Go.Web', 'Palm', 'iPAQ');
    $mobile_token_list = array('Profile/MIDP', 'Configuration/CLDC-', '160×160', '176×220', '240×240', '240×320', '320×240', 'UP.Browser', 'UP.Link', 'SymbianOS', 'PalmOS', 'PocketPC', 'SonyEricsson', 'Nokia', 'BlackBerry', 'Vodafone', 'BenQ', 'Novarra-Vision', 'Iris', 'NetFront', 'HTC_', 'Xda_', 'SAMSUNG-SGH', 'Wapaka', 'DoCoMo', 'iPhone', 'iPod');

    $found_mobile = _is_mobile($mobile_os_list, $useragent_commentsblock) ||
        _is_mobile($mobile_token_list, $useragent);
    if ($found_mobile) {
        return true;
    } else {
        return false;
    }
}

php剔除a标签 不指定

jed , 2018-3-14 10:01 , 代码编程 , 评论(0) , 阅读(1475) , Via 本站原创

//剔除a标签
function tichuA($str){
    $str1 = preg_replace("/<a[^>]*>/","", $str);
    $str2 = preg_replace("/<\/a>/","", $str1);
    return $str2;
}

直接用 floatval($arg) 来转换,既可以保留有效的小数点,也可以去掉后面多余的0, 其中arg 为变量

$number1 = "98.00";
$number2 = "98.76";
echo floatval($number1); //输出结果:98
echo floatval($number2); //输出结果:98.76

php取一天的开始时间 不指定

jed , 2018-3-14 09:57 , 代码编程 , 评论(0) , 阅读(1363) , Via 本站原创

function getTodayBegin(){
    return mktime(0,0,0,date('m'),date('d'),date('Y'));
}

微信的AES加密解密类 不指定

jed , 2018-3-14 09:54 , 代码编程 , 评论(0) , 阅读(1726) , Via 本站原创
本类时基于微信的AES算法提取出来的,原来微信的代码是将明文处理和加密分开,还有微信自己的错误码处理,用起来比较麻烦。所以将微信的代码做了修改,放到了一个类里方便使用.

PHP用于发送网络请求 不指定

jed , 2018-3-14 09:47 , 代码编程 , 评论(0) , 阅读(1585) , Via 本站原创

   /**
     *
     * curl 支持post
     * @param string $base_url 基础链接
     * @param array $query_data 需要请求的数据
     * @param string $method 方法 get/post
     * @param boolean $ssl 关闭ssl验证
     * @param integer $exe_timeout 执行超时时间
     * @param integer $conn_timeout 连接超时时间
     * @param integer $dns_timeout dns超时时间
     */
    function tx_curl($base_url, $query_data, $method = 'get', $ssl = true, $exe_timeout = 10, $conn_timeout = 10, $dns_timeout = 3600)
    {
        $ch = curl_init();
        
        if ( $method == 'get' ) {
            //method get
            if ( ( !empty($query_data) )
                && ( is_array($query_data) )
            ){
                $connect_symbol = (strpos($base_url, '?')) ? '&' : '?';
                foreach($query_data as $key => $val) {
                    if ( is_array($val) ) {
                        $val = serialize($val);
                    }
                    $base_url .= $connect_symbol . $key . '=' . rawurlencode($val);
                    $connect_symbol = '&';
                }
            }
        } else {
            if ( ( !empty($query_data) )
                && ( is_array($query_data) )
            ){
                foreach($query_data as $key => $val) {
                    if ( is_array($val) ) {
                        $query_data[$key] = serialize($val);
                    }
                }
            }
            //method post
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $query_data);
        }
        curl_setopt($ch, CURLOPT_URL, $base_url);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $conn_timeout);
        curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, $dns_timeout);
        curl_setopt($ch, CURLOPT_TIMEOUT, $exe_timeout);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        // 关闭ssl验证
        if($ssl){
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }

        $output = curl_exec($ch);
        
        if ( $output === FALSE )
            $output = '';
            
        curl_close($ch);
        return $output;
    }

根据高德地图获取经纬度 不指定

jed , 2018-3-14 09:42 , 代码编程 , 评论(0) , 阅读(1491) , Via 本站原创

/***********高德地图 根据地址获取经纬度************/
function getCoorByAddr($address)
{
    $key = C('GAODE_KEY');
//    $key = 'd20f62e5a58433a20e75c015a4f054fe';
    $url = "http://restapi.amap.com/v3/geocode/geo?key={$key}&address={$address}";
    $arr = file_get_contents($url);
    $newarr = json_decode($arr, true);
    if($newarr['info']=='OK'){
        $coor = $newarr['geocodes'][0]['location'];
        $coor =explode(',',$coor);
//        var_dump($coor);
        return array(
            'coor_x'=>$coor[0],
            'coor_y'=>$coor[1],
        );
    }
}

PHPExcel导入Excel数据 不指定

jed , 2018-3-14 09:37 , 代码编程 , 评论(0) , 阅读(1741) , Via 本站原创

public function importFromExcel($excel_url)
{
    //Loader::import('phpexcel.PHPExcel');
    Loader::import('phpexcel.PHPExcel.IOFactory');
    // $phpExcel = new \PHPExcel();

    $fileExt = getExt($excel_url);
    if ($fileExt == 'xls') {
        $reader = \PHPExcel_IOFactory::createReader('Excel5');
    } else {
        $reader = \PHPExcel_IOFactory::createReader('Excel2007');
    }
    //$reader = \PHPExcel_IOFactory::createReader('Excel2007');
    //$reader = \PHPExcel_IOFactory::createReader('Excel5');
    $allSheets = $reader->load('/www/FenFa/public'.$excel_url);
    $excel_arr = $allSheets->getSheet(0)->toArray();
    array_shift($excel_arr);
    $data = [];
    foreach ($excel_arr as $k=>$v) {
        if ($v[1]) {
            $data[$k]['data_time']        = strtotime(str_replace('.', '-', $v[0]));
            $data[$k]['cooperation_id']   = $v[1];
            $data[$k]['settlement_price'] = $v[2];
            $data[$k]['settlement_ratio'] = $v[3];
            $data[$k]['settlement_num']   = $v[4];
        }
    }

    foreach ($data as $v) {
        if ($v['cooperation_id']) {
            Db::name('data')->insert($v);
        }
    }
}

php 文件原生上传函数 不指定

jed , 2018-3-14 09:29 , 代码编程 , 评论(0) , 阅读(2156) , Via 本站原创
php 文件原生上传函数

*自定义一个图片等比缩放函数
*@param string $picname 被缩放图片名
*@param string $path 被缩放图片路径
*@param int $maxWidth 图片被缩放后的最大宽度
*@param int $maxHeight 图片被缩放后的最大高度
*@param string $pre 缩放后的图片名前缀,默认为"s_"
*@return boolen 返回布尔值表示成功与否。
*/
function imageResize($picname,$path,$maxWidth,$maxHeight,$pre="s_"){
    $path = rtrim($path,"/")."/";
    //1获取被缩放的图片信息
    $info = getimagesize($path.$picname);
    //获取图片的宽和高
    $width = $info[0];
    $height = $info[1];
    
    //2根据图片类型,使用对应的函数创建画布源。
    switch($info[2]){
        case 1: //gif格式
            $srcim = imagecreatefromgif($path.$picname);
            break;
        case 2: //jpeg格式
            $srcim = imagecreatefromjpeg($path.$picname);
            break;
        case 3: //png格式
            $srcim = imagecreatefrompng($path.$picname);
            break;
       default:
            return false;
            //die("无效的图片格式");
            break;
    }
    //3. 计算缩放后的图片尺寸
    if($maxWidth/$width<$maxHeight/$height){
        $w = $maxWidth;
        $h = ($maxWidth/$width)*$height;
    }else{
        $w = ($maxHeight/$height)*$width;
        $h = $maxHeight;
    }
    //4. 创建目标画布
    $dstim = imagecreatetruecolor($w,$h);

    //5. 开始绘画(进行图片缩放)
    imagecopyresampled($dstim,$srcim,0,0,0,0,$w,$h,$width,$height);

    //6. 输出图像另存为
    switch($info[2]){
        case 1: //gif格式
            imagegif($dstim,$path.$pre.$picname);
            break;
        case 2: //jpeg格式
            imagejpeg($dstim,$path.$pre.$picname);
            break;
        case 3: //png格式
            imagepng($dstim,$path.$pre.$picname);
            break;
    }
  }
分页: 10/81 第一页 上页 5 6 7 8 9 10 11 12 13 14 下页 最后页 [ 显示模式: 摘要 | 列表 ]