2017-07-12 1 views
0

Je souhaite afficher plusieurs images de codes à barres lorsque j'insère le numéro dans la zone de texte. Par exemple, si j'écris 12345, il affichera la première image. Ensuite, quand j'insère un autre numéro 456789, il affichera la deuxième image sous la première image. Mais mon problème est que la deuxième image est la même avec la première image. Quelqu'un peut-il m'aider à vérifier mon code. Mon nom de fichier php est "code39.php".Comment afficher plusieurs images de code à barres en utilisant php html?

?> 
<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
</head> 
<body> 
<form method="GET" action="code39.php"> 

    Code:<br><input type="text" name="code"><br> 
    <input type="submit" name="submit"><br><br> 

</form> 
</body> 
</html> 
<?php 
    ini_set('display_errors',1); 
    error_reporting(E_ALL|E_STRICT);  

    $code = isset($_GET['code']) ? $_GET['code'] :'code' ; 

    $barcode = draw($code); 
    echo $barcode."<br>"; 
    echo $barcode."<br>"; 

?> 

Je donne la moitié du code. Et voici le résultat: enter image description here

+0

Vous voudrez peut-être jeter un oeil à https://github.com/zendframework/zend-barcode et https://docs.zendframework.com/zend-barcode/. – localheinz

+0

@localheinz. Comment lancer ce fichier zendframework? –

+0

Je ne l'ai pas utilisé moi-même, mais d'après ce que j'entends, https://docs.zendframework.com/zend-barcode/intro/ et https://getcomposer.org/doc/00-intro.md sont probablement un bon début points. – localheinz

Répondre

0

J'utilise ce code peut succès.

<?php 
     $Code39 = array(
    '0'=>'111221211', 
    '1'=>'211211112', 
    '2'=>'112211112', 
    '3'=>'212211111', 
    '4'=>'111221112', 
    '5'=>'211221111', 
    '6'=>'112221111', 
    '7'=>'111211212', 
    '8'=>'211211211', 
    '9'=>'112211211', 
    'A'=>'211112112', 
    'B'=>'112112112', 
    'C'=>'212112111', 
    'D'=>'111122112', 
    'E'=>'211122111', 
    'F'=>'112122111', 
    'G'=>'111112212', 
    'H'=>'211112211', 
    'I'=>'112112211', 
    'J'=>'111122211', 
    'K'=>'211111122', 
    'L'=>'112111122', 
    'M'=>'212111121', 
    'N'=>'111121122', 
    'O'=>'211121121', 
    'P'=>'112121121', 
    'Q'=>'111111222', 
    'R'=>'211111221', 
    'S'=>'112111221', 
    'T'=>'111121221', 
    'U'=>'221111112', 
    'V'=>'122111112', 
    'W'=>'222111111', 
    'X'=>'121121112', 
    'Y'=>'221121111', 
    'Z'=>'122121111', 
    '-'=>'121111212', 
    '.'=>'221111211', 
    ' '=>'122111211', 
    '$'=>'121212111', 
    '/'=>'121211121', 
    '+'=>'121112121', 
    '%'=>'111212121', 
    '*'=>'121121211'); 



     $unit='px';//Unit 
     $bw=2;//bar width 
     $height=50*$bw;// px 
     $fs=8*$bw;//Font size 
     $yt=45*$bw; 
     $dx=3*$bw; 
     $x=4*$bw; 
     $y=2.5*$bw; 
     $bl=35*$bw; 


     $unit1='px';//Unit 
     $bw1=2;//bar width 
     $height1=50*$bw1;// px 
     $fs1=8*$bw1;//Font size 
     $yt1=45*$bw1; 
     $dx1=3*$bw1; 
     $x1=4*$bw1; 
     $y1=2.5*$bw1; 
     $bl1=35*$bw1; 


     function checksum($string) 
     { 
      $checksum = 0; 
      $length = strlen($string); 
      $charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'; 

      for($i=0; $i < $length; ++$i) 
      { 
       $checksum += strpos($charset, $string[$i]); 
      } 

      return substr($charset, ($checksum % 43), 1); 
     } 
     function draw($str,$checksum=false){ 
      global $unit,$x,$Code39,$height,$bw; 
      $str=strtoupper($str); 
      if ($checksum) { 
       $str=$str.checksum($str); 
      } 
      $str='*'.$str.'*'; 
      $long=(strlen($str)+3)*12; 
      $width=$bw*$long; 
      $text=str_split($str); 
      $img=''; 
      $img.= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"; 
      $img.= "<svg width='$width$unit' height='$height$unit' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n"; 

      foreach($text as $char){ 
       $img.=drawsymbol($char); 
      } 

      $img.='</svg>'; 

      return $img; 
     } 

     function drawsymbol($char){ 
      global $unit,$Code39,$x,$y,$dx,$bw,$fs,$dx,$yt,$bl; 
      $x+=$bw; 
      $img=''; 
      $img.= '<desc>'.htmlspecialchars($char)."</desc>\n"; 
      $xt=$x+$dx; 
      $img.= "<text x='$xt$unit' y='$yt$unit' font-family='Arial' font-size='$fs'>$char</text>\n"; 
      $val =str_split($Code39[$char]); 
      $len=9; 
      for ($i=0; $i<$len; $i++){ 
       $num=(int)$val[$i]; 
       $w=$bw*$num; 
       if(!($i % 2)){ 
        $img.= "<rect x='$x$unit' y='$y$unit' width='$w$unit' height='$bl$unit' fill='black' stroke-width='0' />\n"; 
       } 
       $x += $w; 
      } 
      return $img; 
     } 






     function checksum1($string1) 
     { 
      $checksum1 = 0; 
      $length1 = strlen($string1); 
      $charset1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'; 

      for($i=0; $i < $length1; ++$i) 
      { 
       $checksum1 += strpos($charset1, $string1[$i]); 
      } 

      return substr($charset1, ($checksum1 % 43), 1); 
     } 
     function draw1($str1,$checksum1=false){ 
      global $unit1,$x1,$Code39,$height1,$bw1; 
      $str1=strtoupper($str1); 
      if ($checksum1) { 
       $str1=$str1.checksum1($str1); 
      } 
      $str1='*'.$str1.'*'; 
      $long1=(strlen($str1)+3)*12; 
      $width1=$bw1*$long1; 
      $text1=str_split($str1); 
      $img1=''; 
      $img1.= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"; 
      $img1.= "<svg width='$width1$unit1' height='$height1$unit1' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n"; 

      foreach($text1 as $char1){ 
       $img1.=drawsymbol1($char1); 
      } 

      $img1.='</svg>'; 

      return $img1; 
     } 

     function drawsymbol1($char1){ 
      global $unit1,$Code39,$x1,$y1,$dx1,$bw1,$fs1,$dx1,$yt1,$bl1; 
      $x1+=$bw1; 
      $img1=''; 
      $img1.= '<desc>'.htmlspecialchars($char1)."</desc>\n"; 
      $xt1=$x1+$dx1; 
      $img1.= "<text x='$xt1$unit1' y='$yt1$unit1' font-family='Arial' font-size='$fs1'>$char1</text>\n"; 
      $val1 =str_split($Code39[$char1]); 
      $len1=9; 
      for ($i=0; $i<$len1; $i++){ 
       $num1=(int)$val1[$i]; 
       $w1=$bw1*$num1; 
       if(!($i % 2)){ 
        $img1.= "<rect x='$x1$unit1' y='$y1$unit1' width='$w1$unit1' height='$bl1$unit1' fill='black' stroke-width='0' />\n"; 
       } 
       $x1 += $w1; 
      } 
      return $img1; 
     } 
    ?> 
    <!DOCTYPE html> 
    <html> 
    <head> 
     <title></title> 
    </head> 
    <body> 
    <form method="GET" action="code39exam.php"> 

     Code 1:&nbsp;<input type="text" name="code"><br><br> 


     Code 2:&nbsp;<input type="text" name="code1"><br><br> 
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
     <input type="submit" name="submit"><br><br> 

    </form> 
    </body> 
    </html> 
    <?php 
     ini_set('display_errors',1); 
     error_reporting(E_ALL|E_STRICT);  

     $code = isset($_GET['code']) ? $_GET['code'] :'code' ; 

     $barcode = draw($code); 
     echo $barcode."<br>"; 


     $code1 = isset($_GET['code1']) ? $_GET['code1'] :'code' ; 

     $barcode1 = draw1($code1); 
     echo $barcode1."<br>"; 

    ?> 

enter image description here