Ankündigung

Einklappen
Keine Ankündigung bisher.

Mit for mehrfach ausführen

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Mit for mehrfach ausführen

    Hallo,

    ich hoffe, ich mache nun alles richtig ( Code Tag usw. )
    Mein Problem: Ich möchte, dass das unten ausgeführte Script sich mehrfach ausführt. Deshalb habe ich eine for- Schleife gesetzt. Nun bekomme ich aber folgende Fehlermeldung:

    Fatal error: Call to undefined function: barcode39() in /usr/.../nullt.php on line 57

    Wie kann ich es realisieren, das das Skript 3 mal ausgeführt wird und das Bild entsprechend $u ( wie in funktion Output Image ) gespeichert wird.

    Habe auch schon versucht, die Schleife nur auf

    PHP-Code:
        switch ($type)
        {
            default:
                    
    $type 1;
            case 
    1:
                    
    Barcode39 ($nullb$width$height$quality$format$text);
                    break;
        } 
    zu beziehen, jedoch auch ohne Erfolg.

    Hier der gesamte Code


    PHP-Code:
    <?php
    for($u=0$u<3$u++)
    {
    $nullb="20003";

    $zeichen=strlen($nullb);

    if (
    $zeichen<="3") { $width="100"; }
    elseif (
    $zeichen=="4") { $width="110"; }
    elseif (
    $zeichen=="5") { $width="130"; }
    elseif (
    $zeichen=="6") { $width="150"; }
    elseif (
    $zeichen=="7") { $width="165"; }
    elseif (
    $zeichen=="8") { $width="185"; }
    elseif (
    $zeichen=="9") { $width="205"; }
    elseif (
    $zeichen=="10") { $width="220"; }
    elseif (
    $zeichen=="11") { $width="240"; }
    elseif (
    $zeichen=="12") { $width="260"; }
    elseif (
    $zeichen=="13") { $width="275"; }
    elseif (
    $zeichen=="14") { $width="295"; }
    elseif (
    $zeichen=="15") { $width="315"; }
    elseif (
    $zeichen=="16") { $width="330"; }
    elseif (
    $zeichen=="17") { $width="350"; }
    elseif (
    $zeichen=="18") { $width="370"; }
    elseif (
    $zeichen=="19") { $width="385"; }
    elseif (
    $zeichen=="20") { $width="405"; }
    elseif (
    $zeichen=="21") { $width="425"; }


    //-----------------------------------------------------------------------------
    // Startup code
    //-----------------------------------------------------------------------------


    if(isset($_GET["text"])) $text=$_GET["text"];
    if(isset(
    $_GET["format"])) $format=$_GET["format"];
    if(isset(
    $_GET["quality"])) $quality=$_GET["quality"];
    if(isset(
    $_GET["width"])) $width=$_GET["width"];
    if(isset(
    $_GET["height"])) $height=$_GET["height"];
    if(isset(
    $_GET["type"])) $type=$_GET["type"];
    if(isset(
    $_GET["nullb"])) $barcode=$_GET["nullb"];


    if (!isset (
    $text)) $text 0// Zeige keine  Zahl unter dem Code an
    if (!isset ($type)) $type 1;
    if (empty (
    $quality)) $quality 100;
    if (empty (
    $width)) $width "$width";
    if (empty (
    $height)) $height 15;
    if (!empty (
    $format)) $format strtoupper ($format);
            else 
    $format="JPEG"// Auszugebendes Format

        
    switch ($type)
        {
            default:
                    
    $type 1;
            case 
    1:
                    
    Barcode39 ($nullb$width$height$quality$format$text);
                    break;
        }


    //-----------------------------------------------------------------------------
    // Generate a Code 3 of 9 barcode
    //-----------------------------------------------------------------------------
    function Barcode39 ($nullb$width$height$quality$format$text)
    {
      switch (
    $format)
            {
                    default:
                            
    $format "JPEG";
                    case 
    "JPEG":
                            
    header ("Content-type: image/jpeg");
                            
    //header("Location: drei.php");
                            
    break;
                    case 
    "PNG":
                            
    header ("Content-type: image/png");
                            
    header("Location: drei.php");
                            break;
                    case 
    "GIF":
                            
    header ("Content-type: image/gif");
                            
    header("Location: drei.php");
                            break;
            }


            
    $im ImageCreate ($width$height)
        or die (
    "Cannot Initialize new GD image stream");
            
    $White ImageColorAllocate ($im255255255);
            
    $Black ImageColorAllocate ($im000);
            
    //ImageColorTransparent ($im, $White);
            
    ImageInterLace ($im1);



            
    $NarrowRatio 20;
            
    $WideRatio 55// org 55
            
    $QuietRatio 35;


            
    $nChars = (strlen($nullb)+2) * (($NarrowRatio) + ($WideRatio) + ($QuietRatio));
            
    $Pixels $width $nChars;
            
    $NarrowBar = (int)(20 $Pixels); // Org 20
            
    $WideBar = (int)(55 $Pixels);
            
    $QuietBar = (int)(35 $Pixels);


            
    $ActualWidth = (($NarrowBar 6) + ($WideBar*3) + $QuietBar) * (strlen ($nullb)+2);

            if ((
    $NarrowBar == 0) || ($NarrowBar == $WideBar) || ($NarrowBar == $QuietBar) || ($WideBar == 0) || ($WideBar == $QuietBar) || ($QuietBar == 0))
            {
                    
    ImageString ($im100"x zu klein !"$Black);
                    
    OutputImage ($im$format$quality);
                    exit;
            }

            
    $CurrentBarX = (int)(($width $ActualWidth) / 2);
            
    $Color $White;

            
    $BarcodeFull "*".strtoupper ($nullb)."*";
            
    settype ($BarcodeFull"string");

            
    $FontNum 3// orginal == 3
            
    $FontHeight ImageFontHeight ($FontNum);
            
    $FontWidth ImageFontWidth ($FontNum);
            if (
    $text != 0)
            {
                    
    $CenterLoc = (int)(($width-1) / 2) - (int)(($FontWidth strlen($BarcodeFull)) / 2);
                    
    ImageString ($im$FontNum$CenterLoc$height-$FontHeight"$BarcodeFull"$Black);
            }
            else
            {
                
    $FontHeight=-2;
            }


            for (
    $i=0$i<strlen($BarcodeFull); $i++)
            {
                    
    $StripeCode Code39 ($BarcodeFull[$i]);


                    for (
    $n=0$n 9$n++)
                    {
                            if (
    $Color == $White$Color $Black;
                            else 
    $Color $White;


                            switch (
    $StripeCode[$n])
                            {
                                    case 
    '0':
                                            
    ImageFilledRectangle ($im$CurrentBarX0$CurrentBarX+$NarrowBar$height-1-$FontHeight-2$Color);
                                            
    $CurrentBarX += $NarrowBar;
                                            break;


                                    case 
    '1':
                                            
    ImageFilledRectangle ($im$CurrentBarX0$CurrentBarX+$WideBar$height-1-$FontHeight-2$Color);
                                            
    $CurrentBarX += $WideBar;
                                            break;
                            }
                    }


                    
    $Color $White;
                    
    ImageFilledRectangle ($im$CurrentBarX0$CurrentBarX+$QuietBar$height-1-$FontHeight-2$Color);
                    
    $CurrentBarX += $QuietBar;
            }


            
    OutputImage ($im$format$quality);
    }

    //-----------------------------------------------------------------------------
    // Output an image to the browser
    //-----------------------------------------------------------------------------

    function OutputImage ($im$format$quality)
    {
            switch (
    $format)
            {
                    case 
    "JPEG":

                    if (
    $u=="0") { ImageJPEG ($im'/usr/.../null0.jpeg'); }
                    if (
    $u=="1") { ImageJPEG ($im'/usr/.../null1.jpeg'); }
                    if (
    $u=="2") { ImageJPEG ($im'/usr/.../null2.jpeg'); }

                    
    imageDestroy($im);
                            break;

                    case 
    "PNG":
                    
    ImagePNG ($im'/usr/.../null.png');
                    
    imageDestroy($im);
                           break;

                    case 
    "GIF":
                    
    ImageGIF ($im'/usr/.../null.gif');
                    
    imageDestroy($im);

                            break;
            }
    }


    //-----------------------------------------------------------------------------
    // Returns the Code 3 of 9 value for a given ASCII character
    //-----------------------------------------------------------------------------
    function Code39 ($Asc)
    {
            switch (
    $Asc)
            {
                    case 
    ' ':
                            return 
    "011000100";
                    case 
    '$':
                            return 
    "010101000";
                    case 
    '%':
                            return 
    "000101010";
                    case 
    '*':
                            return 
    "010010100"// * Start/Stop
                    
    case '+':
                            return 
    "010001010";
                    case 
    '|':
                            return 
    "010000101";
                    case 
    '.':
                            return 
    "110000100";
                    case 
    '/':
                            return 
    "010100010";
                    case 
    '-':
                            return 
    "010000101";
                    case 
    '0':
                            return 
    "000110100";
                    case 
    '1':
                            return 
    "100100001";
                    case 
    '2':
                            return 
    "001100001";
                    case 
    '3':
                            return 
    "101100000";
                    case 
    '4':
                            return 
    "000110001";
                    case 
    '5':
                            return 
    "100110000";
                    case 
    '6':
                            return 
    "001110000";
                    case 
    '7':
                            return 
    "000100101";
                    case 
    '8':
                            return 
    "100100100";
                    case 
    '9':
                            return 
    "001100100";
                    case 
    'A':
                            return 
    "100001001";
                    case 
    'B':
                            return 
    "001001001";
                    case 
    'C':
                            return 
    "101001000";
                    case 
    'D':
                            return 
    "000011001";
                    case 
    'E':
                            return 
    "100011000";
                    case 
    'F':
                            return 
    "001011000";
                    case 
    'G':
                            return 
    "000001101";
                    case 
    'H':
                            return 
    "100001100";
                    case 
    'I':
                            return 
    "001001100";
                    case 
    'J':
                            return 
    "000011100";
                    case 
    'K':
                            return 
    "100000011";
                    case 
    'L':
                            return 
    "001000011";
                    case 
    'M':
                            return 
    "101000010";
                    case 
    'N':
                            return 
    "000010011";
                    case 
    'O':
                            return 
    "100010010";
                    case 
    'P':
                            return 
    "001010010";
                    case 
    'Q':
                            return 
    "000000111";
                    case 
    'R':
                            return 
    "100000110";
                    case 
    'S':
                            return 
    "001000110";
                    case 
    'T':
                            return 
    "000010110";
                    case 
    'U':
                            return 
    "110000001";
                    case 
    'V':
                            return 
    "011000001";
                    case 
    'W':
                            return 
    "111000000";
                    case 
    'X':
                            return 
    "010010001";
                    case 
    'Y':
                            return 
    "110010000";
                    case 
    'Z':
                            return 
    "011010000";
                    default:
                            return 
    "011000100";
            }
    }
    // E
    ?>
    Hoffe, ich bekomme eine sinnvolle Hilfestellung´und verbleibe mit erwartungsvollen Grüßen.

    Falke

  • #2
    Die Funktionen innerhalb der for-Schleife zu definieren, ist absoluter Unfug.
    [SIZE="1"]RGB is totally confusing - I mean, at least #C0FFEE should be brown, right?[/SIZE]

    Kommentar


    • #3
      Wie wäre es, wenn du für den Anfang die Funktionen nach oben oder in eine separate Datei schreibst anstatt sie innerhalb der for-Schleife zu definieren. Die Fehlermeldung deutet ja schon darauf hin dass es eher ein Problem mit deinen Funktions-Definitionen gibt als mit der Schleife.

      Edit: ninja'd
      [IMG]https://g.twimg.com/twitter-bird-16x16.png[/IMG][URL="https://twitter.com/fschmengler"]@fschmengler[/URL] - [IMG]https://i.stack.imgur.com/qh235.png[/IMG][URL="https://stackoverflow.com/users/664108/fschmengler"]@fschmengler[/URL] - [IMG]http://i.imgur.com/ZEqflLv.png[/IMG] [URL="https://github.com/schmengler/"]@schmengler[/URL]
      [URL="http://www.schmengler-se.de/"]PHP Blog[/URL] - [URL="http://www.schmengler-se.de/magento-entwicklung/"]Magento Entwicklung[/URL] - [URL="http://www.css3d.net/"]CSS Ribbon Generator[/URL]

      Kommentar

      Lädt...
      X