将数字转换为大写人民币格式的函数0+

83,535 views / 2010.06.02 / 2:02 下午

这个函数用来把数字转换为人民币大写格式,经过测试已经接近完美。如果有bug,欢迎反馈!

function toCNFormat($data) {
 $data = strpos($data, ".") === false? $data . ".00":$data;
 if (!preg_match("/^[0-9\.]+$/", $data))return "";
 $capnum = array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
 $capdigit = array("", "拾", "佰", "仟");
 $subdata = explode(".", $data);
 $yuan = $subdata[0];
 $j = 0;
 $nonzero = 0;
 for($i = 0;$i < strlen($subdata[0]);$i++) {
  if (0 == $i) {
   if ($subdata[1]) {
    $cncap = substr($subdata[0], -1, 1) != 0?"元":"元零";
   } else {
    $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++;
 }
 
 if ($subdata[1]) {
  $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 . "整";
 $cncap = preg_replace("/(零)+/", "\\1", $cncap);
 $cncap = str_replace("零整", "整", $cncap);
 return $cncap;
}
echo toCNFormat("110502.35");
Categories: 分享 Tags: ,

这里解释下config.php中的配置信息,供大家配置时候使用

$seccodedata['type'] = 0; //0英文图片验证码 1中文图片验证码 2Flash 验证码 3语音验证码
$seccodedata['width'] = 150;//验证码宽度
$seccodedata['height'] = 60;;//验证码高度
$seccodedata['background'] = 1;//是否需要随机背景
$seccodedata['adulterate'] = 1;//是否随机混淆
$seccodedata['ttf'] = 1;//使用ttf字体
$seccodedata['angle'] = 1;//自动旋转
$seccodedata['color'] = 1;//随机颜色
$seccodedata['size'] = 1;//字体随机大小
$seccodedata['shadow'] = 1;//添加字体阴影
$seccodedata['animator'] = 1;//这个是关键,能动的gif验证码
$timestamp = time();
$_DCOOKIE = array();
$seccode = 0;
$charset = "GBK";
$GLOBALS['auth_key'] = "duyipeng";//这个越复杂越好,算是密钥
define("_SITE_ROOT_",dirname(__FILE__)."/");
define("_SESSION_PATH_",_SITE_ROOT_."session");
session_save_path(_SESSION_PATH_);
session_start();
//这里定义session回收命令 定义seesion存储路径是为了方便多台机器部署

index.php+test.php是测试例子。

个人感觉这个验证码便于阅读,又不容易被破解,很不错。

ps.不要使用cookie,不然容易被cc.

下载地址:http://cid-7826486a7f7dc8a9.skydrive.live.com/self.aspx/.Public/seccode.rar 解压密码:www.71j.cn

Categories: 分享 Tags: ,

一个全面获取图象信息的函数,包括EXIF信息0+

90,956 views / 2010.03.09 / 12:12 下午

呵呵,中文化的EXIF解析,是不是你想要的呢?使用此方法,可以任意改写出你所需要的东东。

<?
/**
* 获取图象信息的函数
*
* 一个全面获取图象信息的函数
*
* @access public
* @param string $img 图片路径
* @return array
*/
function GetImageInfoVal($ImageInfo,$val_arr) {
    $InfoVal    =    "未知";
    foreach($val_arr as $name=>$val) {
        if ($name==$ImageInfo) {
            $InfoVal    =    &$val;
            break;
        }
    }
    return $InfoVal;
}
function GetImageInfo($img) {
 
    $imgtype            =    array("", "GIF", "JPG", "PNG", "SWF", "PSD", "BMP", "TIFF(intel byte order)", "TIFF(motorola byte order)", "JPC", "JP2", "JPX", "JB2", "SWC", "IFF", "WBMP", "XBM");
    $Orientation        =    array("", "top left side", "top right side", "bottom right side", "bottom left side", "left side top", "right side top", "right side bottom", "left side bottom");
    $ResolutionUnit        =    array("", "", "英寸", "厘米");
    $YCbCrPositioning    =    array("", "the center of pixel array", "the datum point");
    $ExposureProgram    =    array("未定义", "手动", "标准程序", "光圈先决", "快门先决", "景深先决", "运动模式", "肖像模式", "风景模式");
    $MeteringMode_arr    =    array(
        "0"        =>    "未知",
        "1"        =>    "平均",
        "2"        =>    "中央重点平均测光",
        "3"        =>    "点测",
        "4"        =>    "分区",
        "5"        =>    "评估",
        "6"        =>    "局部",
        "255"    =>    "其他"
        );
    $Lightsource_arr    =    array(
        "0"        =>    "未知",
        "1"        =>    "日光",
        "2"        =>    "荧光灯",
        "3"        =>    "钨丝灯",
        "10"    =>    "闪光灯",
        "17"    =>    "标准灯光A",
        "18"    =>    "标准灯光B",
        "19"    =>    "标准灯光C",
        "20"    =>    "D55",
        "21"    =>    "D65",
        "22"    =>    "D75",
        "255"    =>    "其他"
        );
    $Flash_arr            =    array(
        "0"        =>    "flash did not fire",
        "1"        =>    "flash fired",
        "5"        =>    "flash fired but strobe return light not detected",
        "7"        =>    "flash fired and strobe return light detected",
        );
 
    $exif = exif_read_data ($img,"IFD0");
    if ($exif===false) {
        $new_img_info    =    array ("文件信息"        =>    "没有图片EXIF信息");
    }
    else
    {
        $exif = exif_read_data ($img,0,true);
        $new_img_info    =    array (
            "文件信息"        =>    "-----------------------------",
            "文件名"        =>    $exif[FILE][FileName],
            "文件类型"        =>    $imgtype[$exif[FILE][FileType]],
            "文件格式"        =>    $exif[FILE][MimeType],
            "文件大小"        =>    $exif[FILE][FileSize],
            "时间戳"        =>    date("Y-m-d H:i:s",$exif[FILE][FileDateTime]),
            "图像信息"        =>    "-----------------------------",
            "图片说明"        =>    $exif[IFD0][ImageDescription],
            "制造商"        =>    $exif[IFD0][Make],
            "型号"            =>    $exif[IFD0][Model],
            "方向"            =>    $Orientation[$exif[IFD0][Orientation]],
            "水平分辨率"    =>    $exif[IFD0][XResolution].$ResolutionUnit[$exif[IFD0][ResolutionUnit]],
            "垂直分辨率"    =>    $exif[IFD0][YResolution].$ResolutionUnit[$exif[IFD0][ResolutionUnit]],
            "创建软件"        =>    $exif[IFD0][Software],
            "修改时间"        =>    $exif[IFD0][DateTime],
            "作者"            =>    $exif[IFD0][Artist],
            "YCbCr位置控制"    =>    $YCbCrPositioning[$exif[IFD0][YCbCrPositioning]],
            "版权"            =>    $exif[IFD0][Copyright],
            "摄影版权"        =>    $exif[COMPUTED][Copyright.Photographer],
            "编辑版权"        =>    $exif[COMPUTED][Copyright.Editor],
            "拍摄信息"        =>    "-----------------------------",
            "Exif版本"        =>    $exif[EXIF][ExifVersion],
            "FlashPix版本"    =>    "Ver. ".number_format($exif[EXIF][FlashPixVersion]/100,2),
            "拍摄时间"        =>    $exif[EXIF][DateTimeOriginal],
            "数字化时间"    =>    $exif[EXIF][DateTimeDigitized],
            "拍摄分辨率高"    =>    $exif[COMPUTED][Height],
            "拍摄分辨率宽"    =>    $exif[COMPUTED][Width],
            /*
            The actual aperture value of lens when the image was taken.
            Unit is APEX.
            To convert this value to ordinary F-number(F-stop),
            calculate this value's power of root 2 (=1.4142).
            For example, if the ApertureValue is '5', F-number is pow(1.41425,5) = F5.6.
            */
            "光圈"            =>    $exif[EXIF][ApertureValue],
            "快门速度"        =>    $exif[EXIF][ShutterSpeedValue],
            "快门光圈"        =>    $exif[COMPUTED][ApertureFNumber],
            "最大光圈值"    =>    "F".$exif[EXIF][MaxApertureValue],
            "曝光时间"        =>    $exif[EXIF][ExposureTime],
            "F-Number"        =>    $exif[EXIF][FNumber],
            "测光模式"        =>    GetImageInfoVal($exif[EXIF][MeteringMode],$MeteringMode_arr),
            "光源"            =>    GetImageInfoVal($exif[EXIF][LightSource], $Lightsource_arr),
            "闪光灯"        =>    GetImageInfoVal($exif[EXIF][Flash], $Flash_arr),
            "曝光模式"        =>    ($exif[EXIF][ExposureMode]==1?"手动":"自动"),
            "白平衡"        =>    ($exif[EXIF][WhiteBalance]==1?"手动":"自动"),
            "曝光程序"        =>    $ExposureProgram[$exif[EXIF][ExposureProgram]],
            /*
            Brightness of taken subject, unit is APEX. To calculate Exposure(Ev) from BrigtnessValue(Bv), you must add SensitivityValue(Sv).
            Ev=Bv+Sv   Sv=log((ISOSpeedRating/3.125),2)
            ISO100:Sv=5, ISO200:Sv=6, ISO400:Sv=7, ISO125:Sv=5.32.
            */
            "曝光补偿"        =>    $exif[EXIF][ExposureBiasValue]."EV",
            "ISO感光度"        =>    $exif[EXIF][ISOSpeedRatings],
            "分量配置"        =>    (bin2hex($exif[EXIF][ComponentsConfiguration])=="01020300"?"YCbCr":"RGB"),//'0x04,0x05,0x06,0x00'="RGB" '0x01,0x02,0x03,0x00'="YCbCr"
            "图像压缩率"    =>    $exif[EXIF][CompressedBitsPerPixel]."Bits/Pixel",
            "对焦距离"        =>    $exif[COMPUTED][FocusDistance]."m",
            "焦距"            =>    $exif[EXIF][FocalLength]."mm",
            "等价35mm焦距"    =>    $exif[EXIF][FocalLengthIn35mmFilm]."mm",
            /*
            Stores user comment. This tag allows to use two-byte character code or unicode. First 8 bytes describe the character code. 'JIS' is a Japanese character code (known as Kanji).
            '0x41,0x53,0x43,0x49,0x49,0x00,0x00,0x00':ASCII
            '0x4a,0x49,0x53,0x00,0x00,0x00,0x00,0x00':JIS
            '0x55,0x4e,0x49,0x43,0x4f,0x44,0x45,0x00':Unicode
            '0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00':Undefined
            */
            "用户注释编码"    =>    $exif[COMPUTED][UserCommentEncoding],
            "用户注释"        =>    $exif[COMPUTED][UserComment],
            "色彩空间"        =>    ($exif[EXIF][ColorSpace]==1?"sRGB":"Uncalibrated"),
            "Exif图像宽度"    =>    $exif[EXIF][ExifImageLength],
            "Exif图像高度"    =>    $exif[EXIF][ExifImageWidth],
            "文件来源"        =>    (bin2hex($exif[EXIF][FileSource])==0x03?"digital still camera":"unknown"),
            "场景类型"        =>    (bin2hex($exif[EXIF][SceneType])==0x01?"A directly photographed image":"unknown"),
            "缩略图文件格式"    =>    $exif[COMPUTED][Thumbnail.FileType],
            "缩略图Mime格式"    =>    $exif[COMPUTED][Thumbnail.MimeType]
        );
    }
    return $new_img_info;
}
 
//Example
 
print_r(GetImageInfo("DSC00596.JPG"));
 
?>
Categories: 分享 Tags:

linux系统dig和nslookup的安装3+

116,884 views / 2010.01.28 / 1:01 下午

nslookup是常用来查询本机域名解析情况的命令,但是一些linux系统下默认无此命令。我们可以通过安装一个包来使该命令生效,这个包中也包括dig命令。

Ubuntu:

# sudo apt-get install dnsutils

Debian:

# apt-get update
# apt-get install dnsutils

Fedora / Centos:

# yum install bind-utils
Categories: 分享 Tags: , ,

php curl cookie 存取示例1+

125,778 views / 2009.12.02 / 1:01 下午

好多人发来消息询问curl存取cookie文件的问题,杜工并不觉得这是个难点,因为只看手册就可以很容易把握。下面给个例子,看完后就全都明了了:

<?php
$cookie_jar_index = 'cookie.txt';
 
$url = "http://www.71j.cn/perl/login.pl";
$params = "username=dudu&password=****";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar_index);
//curl_setopt($ch, CURLOPT_COOKIE, "fruit=apple; colour=red");
//上面代码是直接传递cookie信息,而非文件
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params); 
//curl_setopt($ch, CURLOPT_NOBODY, 1);//这个不能打开,否则无法生成cookie文件
ob_start();
curl_exec($ch);
curl_close($ch);
ob_clean();
 
$url = "http://www.71j.cn/perl/myfavorites.pl";
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $url);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar_index);
ob_start();
curl_exec($ch2);
curl_close($ch2);
$rs = ob_get_contents(); //$rs就是返回的内容
ob_clean();
 
print_r($rs);
 
?>
Categories: 分享 Tags: , ,