顯示code39條碼的PHP類

來源:互聯網
上載者:User
<?
/***********************************************************************
                       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;
    }
}
?>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.