仓酷云

标题: PHP网页设计显示code39条形码的PHP类 [打印本页]

作者: 爱飞    时间: 2015-2-4 00:12
标题: PHP网页设计显示code39条形码的PHP类
培训的第四阶段,就是应用PHP语言开发实际的程序。以结合实际的项目开发来进行学习,效果真的很好,在学习完之后就开始练习,能比较容易掌握所学的知识,这是学校的学习所没法比的。条形码|显示   <?
/***********************************************************************
                       Written by caocao
                       caocao@eastday.com
                       http://nethermit.yeah.net
                       
                       显示code39条形码的类
                       利用办法:
                       $convert=new code39;
                       $str=$convert->decode($str);
***********************************************************************/

class pattenclass
{
    var
$color;
    var
$width;
    function
pattenclass($color,$width)
    {
        
$this->color=$color;
        
$this->width=$width;
    }
}

class
code39
{
    var
$zoom;
    var
$height;
    var
$patten=array();
    function
code39($zoom, $height)
    {
        
$zoom=intval($zoom);
        
$this->zoom=$zoom<1||$zoom>20?3:$zoom;
        
$height=intval($height);
        
$this->height=$height<1||$height>80?30:$height;
        
$this->patten[]=new pattenclass("#FFFFFF",1*$this->zoom);
        
$this->patten[]=new pattenclass("#FFFFFF",3*$this->zoom);
        
$this->patten[]=new pattenclass("#000000",1*$this->zoom);
        
$this->patten[]=new pattenclass("#000000",3*$this->zoom);
    }
    function
makecode($code)//code39解码
   
{
        switch (
$code)
        {
            case
"0":return ("202130302");
            case
"1":return ("302120203");
            case
"2":return ("203120203");
            case
"3":return ("303120202");
            case
"4":return ("202130203");
            case
"5":return ("302130202");
            case
"6":return ("203130202");
            case
"7":return ("202120303");
            case
"8":return ("302120302");
            case
"9":return ("203120302");
            case
"A":return ("302021203");
            case
"B":return ("203021203");
            case
"C":return ("303021202");
            case
"D":return ("202031203");
            case
"E":return ("302031202");
            case
"F":return ("203031202");
            case
"G":return ("202021303");
            case
"H":return ("302021302");
            case
"I":return ("203021300");
            case
"J":return ("202031302");
            case
"K":return ("302020213");
            case
"L":return ("203020213");
            case
"M":return ("303020212");
            case
"N":return ("202030213");
            case
"O":return ("302030212");
            case
"P":return ("203030212");
            case
"Q":return ("202020313");
            case
"R":return ("302020312");
            case
"S":return ("203020312");
            case
"T":return ("202030312");
            case
"U":return ("312020203");
            case
"V":return ("213020203");
            case
"W":return ("313020202");
            case
"X":return ("212030203");
            case
"Y":return ("312030202");
            case
"Z":return ("213030202");
            case
"-":return ("212020303");
            case
".":return ("312020302");
            case
" ":return ("213020302");
            case
"*":return ("212030302");
            case
"$":return ("212121202");
            case
"/":return ("212120212");
            case
"+":return ("212021212");
            case
"%":return ("202121212");
        }
        return (
"212030302");
    }
    function
display($code)//输入单个字符
   
{
        
$output="";
        for (
$i=0;$i<9;$i++)
            
$output.="<td height=".$this->height." bgcolor=".$this->patten[$code[$i]]->color." width=".$this->patten[$code[$i]]->width."></td>";
        return
$output;
    }
    function
decode($code)//全体输入
   
{
        
$output="<table width=".($this->height/2*(strlen($code)+2)*$this->zoom)." height=".$this->height." border=0 cellspacing=0 cellpadding=0 align=\"center\"><tr>";
        
$output.=$this->display($this->makecode("*"));
        
$output.="<td height=".$this->height." bgcolor=".$this->patten[0]->color." width=".$this->patten[0]->width."></td>";
        
$length=strlen($code);
        for (
$i=0;$i<$length;$i++)
        {
            
$output.=$this->display($this->makecode($code[$i]));
            
$output.="<td height=".$this->height." bgcolor=".$this->patten[0]->color." width=".$this->patten[0]->width."></td>";
        }
        
$output.=$this->display($this->makecode("*"));
        
$output.="</tr></table>";
        return
$output;
    }
}
?>
最近陆续的有人问我学习php的心得,现在整理为下面,希望可以对大家有些帮助。
作者: 柔情似水    时间: 2015-2-4 09:57
使用 jquery 等js框架的时候,要随时注意浏览器的更新情况,不然很容易发生框架不能使用。
作者: 飘飘悠悠    时间: 2015-2-8 08:24
其实也不算什么什么心得,在各位大侠算是小巫见大巫了吧,望大家不要见笑,若其中有错误的地方请各位大虾斧正。
作者: 活着的死人    时间: 2015-2-25 02:54
本文当是我的笔记啦,遇到的问题随时填充
作者: 深爱那片海    时间: 2015-3-2 01:33
有时候汉字的空格也能导致页面出错,所以在写代码的时候,要输入空格最好用引文模式。
作者: 谁可相欹    时间: 2015-3-2 04:15
其实也不算什么什么心得,在各位大侠算是小巫见大巫了吧,望大家不要见笑,若其中有错误的地方请各位大虾斧正。
作者: 蒙在股里    时间: 2015-3-5 15:23
在我安装pear包的时候老是提示,缺少某某文件,才发现 那群extension 的排列是应该有一点的顺序,而我安装的版本的排序不是正常的排序。没办法我只好把那群冒号加了上去,只留下我需要使用的扩展。
作者: 金色的骷髅    时间: 2015-3-12 08:52
多看优秀程序员编写的代码,仔细理解他们解决问题的方法,对自身有很大的帮助。
作者: 兰色精灵    时间: 2015-3-19 19:17
基础有没有对学习php没有太大区别,关键是兴趣。
作者: 简单生活    时间: 2015-3-21 09:22
要进行开发,搭建环境是首先需要做的事,windows下面我习惯把环境那个安装在C盘下面,因为我配的环境经常出现诡异事件,什么事都没做环境有的时候就不能用啦。
作者: 变相怪杰    时间: 2015-3-26 10:53
本人接触php时间不长,算是phper中的小菜鸟一只吧。由于刚开始学的时候没有名师指,碰过不少疙瘩,呗很多小问题卡过很久,白白浪费不少宝贵的时间,在次分享一些子的学习的心得。
作者: 老尸    时间: 2015-4-4 19:35
作为一个合格的coder 编码的规范是必须,命名方面我推崇“驼峰法”,另外就是自己写的代码最好要带注释,不然时间长了,就算是自己的代码估计看起来都费事,更不用说别人拉。
作者: 山那边是海    时间: 2015-4-5 18:56
要进行开发,搭建环境是首先需要做的事,windows下面我习惯把环境那个安装在C盘下面,因为我配的环境经常出现诡异事件,什么事都没做环境有的时候就不能用啦。
作者: 冷月葬花魂    时间: 2015-4-16 14:09
基础有没有对学习php没有太大区别,关键是兴趣。
作者: 灵魂腐蚀    时间: 2015-4-17 11:01
刚开始安装php的时候,我图了个省事,把php的扩展全都打开啦(就是把php.ini 那一片 extension 前面的冒号全去掉啦),这样自然有好处,以后不用再需要什么功能再来打开。
作者: 精灵巫婆    时间: 2015-5-2 15:20
真正的方向了,如果将来要去开发团队,你一定要学好smarty ,phplib这样的模板引擎,
作者: 小女巫    时间: 2015-5-8 20:56
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
作者: 分手快乐    时间: 2015-6-9 18:17
Apache不是非得用80或者8080端口的,我刚开始安得时候就是80端口老占用,就用了个 81端口,结果照常,就是输localhost的时候,应该输入为 localhost:81
作者: 小魔女    时间: 2015-6-11 02:40
php里的数组为空的时候是不能拿来遍历的;(这个有点低级啊,不过我刚被这个边界问题墨迹了好长一会)
作者: admin    时间: 2015-6-16 22:50
装在C盘下面可以利用windows的ghost功能可以还原回来(顺便当做是重转啦),当然啦我的编译目录要放在别的盘下,不然自己的劳动成果就悲剧啦。




欢迎光临 仓酷云 (http://ckuyun.com/) Powered by Discuz! X3.2