PHP价格转财务大写 不指定

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

function currencyToChinese($data)
{
    $data = str_replace(',', '', $data);

    if ($data == '') {
        return '';
    }

    $prefix = '';
    $cncap = '';

    if ($data < 0) {
        $prefix .= '负';
        $data = substr($data, 1, strlen($data) - 1);
    }

    $capnum = array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
    $capdigit = array("", "拾", "佰", "仟");
    $subdata = explode(".", $data);
    if (!isset($subdata[1])) {
        $subdata[1] = 0;
    }

    if (intval($subdata[0]) == 0 && intval($subdata[1]) == 0) {
        return $prefix . "零元整";
    }

    $yuan = $subdata[0];
    $j = 0; $nonzero = 0;
    for ($i = 0; $i < strlen($subdata[0]); $i++) {
        if (0 == $i) { //确定个位
            if (intval($subdata[1]) != 0) {
                if (substr($subdata[0], -1, 1) == 0) {
                    $cncap .= "元零";
                } else {
                    $cncap .= "元";
                }
            } else {
                if (intval($subdata[0]) != 0) {
                    $cncap = "元";
                }

            }
        }
        if (4 == $i) {
            $j = 0;
            $nonzero = 0;
            $cncap = "万" . $cncap;
        } //确定万位
        if (8 == $i) {
            $j = 0;
            $nonzero=0;
            $cncap="亿" . $cncap;
        } //确定亿位
        $numb = substr($yuan, -1, 1); //截取尾数
        $cncap = ($numb) ?
            $capnum[$numb] . $capdigit[$j] . $cncap : (($nonzero)?"零" . $cncap : $cncap);
        $nonzero = ($numb) ? 1 : $nonzero;
        $yuan = substr($yuan, 0, strlen($yuan)-1); //截去尾数
        $j++;
    }
    $chiao = '';
    $cent = '';
    if (intval($subdata[1]) != 0) {
        $chiao = (substr($subdata[1], 0, 1)) ?
            $capnum[substr($subdata[1], 0, 1)] . "角" : "零";
        $cent = (substr($subdata[1], 1, 1)) ?
            $capnum[substr($subdata[1], 1, 1)] . "分" : "零分";
    }

    $cncap .= $chiao.$cent;
    if (substr($subdata[1], -1, 1) === '0') {
        $cncap .= "整";
    }
    $cncap = preg_replace("/(零)+/", "\\1", $cncap); //合并连续“零”

    if (intval($subdata[0]) == 0) {
        $cncap = preg_replace("/(元零)+/", "", $cncap);
        $cncap = preg_replace("/(元)+/", "", $cncap);
    }
    if (intval($subdata[1]) == 0 || substr($subdata[1], -1, 1) === '0') {
        $cncap = preg_replace("/(零分)+/", "", $cncap);
    }

    return $prefix . $cncap;
}

PHP字符编码转换 不指定

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

<?php

function characet($data,$code='UTF-8'){
        if( !empty($data) ){
            $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
            if( $fileType != $code){
                $data = mb_convert_encoding($data ,$code, $fileType);
            }
        }
        return $data;
    }
?>

获取数组中指定key的值 不指定

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

function getKeyValues($arr, $key)
{
    $ret = [];

    foreach ($arr as $row) {
        if (is_array($row) && array_key_exists($key, $row)) {
            $ret[] = $row[$key];
        } elseif ($row instanceof \ArrayObject) {
            $row->offsetExists($key) && $ret[] = $row->offsetGet($key);
        }
    }

    return $ret;
}

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

jed , 2018-3-14 10:02 , 代码编程 , 评论(0) , 阅读(223) , 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) , 阅读(231) , 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) , 阅读(198) , Via 本站原创

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

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

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

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

jed , 2018-3-14 09:47 , 代码编程 , 评论(0) , 阅读(236) , 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) , 阅读(196) , 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],
        );
    }
}
分页: 3/26 第一页 上页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]