Zeilen umbrüche in Text-Datei

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

  • Zeilen umbrüche in Text-Datei

    Hi @ all,

    ich bin neu hier und habe ein Problem mit dem einlesen von Daten aus einer Text-Datei.

    Ich habe schon gesucht aber nichts entspechendes gefunden.

    Zum Problem:

    Ich möchte aus einer Text-Datei Datensätze einlesen die mit <EOH> beginnen und mit <EOR> enden. Soweit so gut, wenn eho und eor in einer Zeile stehen. Es gibt verschiedene Programme die aber beim erstellen der Textdatei Zeilenumbrüche einfügen.
    Wenn das der Fall ist werden Daten nicht richtig übernommen.

    Das ist ein Teil des Codes zum einlesen der Daten:

    PHP-Code:
    // Can enter this procedure with $string set to either <CALL:x> which is a valid QSO
            // which needs to be processed or set to <EOH> in which case we need to read any blank
            // lines until the first QSO
             
    if (stristr($string,"<EOH>"))
                
    // Skip any blank lines
                 
    while ($string == "\n" || $string == "\r\n")
                    
    $string fgets ($file1024); 

            
    // process the first valid ADIF line
            
    readADIFQSO ($string, &$qso_data, &$band_found, &$freq_found);//

            
    while (($string fgets ($file,1024)))
            {
                
    // Skip any blank lines
                 
    if ($string == "\n" || $string == "\r\n")
                    continue; 

                while (!
    $EOR)
                {
                    
    readADIFQSO ($string, &$qso_data, &$band_found, &$freq_found);//

                    // Check for End of Record
                    
    if (stristr($string,"<EOR>"))
                        
    $EOR 1;
                    else
                        
    $string fgets($file,1024);

                } 

                
    // End of Record. If no <BAND> data has been found then 
                // convert the frequency to band
                
    if ($band_found == 0)
                    
    // Convert the frequency to band
                    
    $qso_data['band'] = convertFrequencyBand ($qso_data['freq']); 
    Der Fehler liegt warscheinlich bei den skip blank lines.

    Für euere hilfe schonmal besten dank im voraus.

    Plattform Windos XP mit Wamp Server 1.6.0
    mfg

    Michael DD4MS

  • #2
    PHP-Code:
    $datei 'deine_datei.ext';
    $content file($datei);
    $suche = array();
    foreach(
    $content as $wert){
        if(
    strpos($wert,'<EOH>') !== false && strpos($wert,'<EOR>') !== false){
            
    $suche[] = trim($wert);
        }

    Am Ende solltest du ein Array suchen haben, dass alle Zeilen enthält, <EOR> und <EOH> enthalten.

    Gruss

    tobi
    Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

    [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
    Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

    Kommentar


    • #3
      hi jahlives,

      danke für die rasche Antwort.
      Ich bin mir allerdings nicht sicher wo ich den Code einbauen soll und ob er das richtige ist.

      Die Datei ist etwas zu groß, um sie hier ganz zu posten.

      Ich füge sie mal als Datei an.

      Ab Zeile 526 wird es interessant, alles vorher sind nur umwandlungen.
      Zuletzt geändert von dd4ms; 17.01.2006, 10:37.
      mfg

      Michael DD4MS

      Kommentar


      • #4
        seltsam hier nochmal die Datei
        Angehängte Dateien
        mfg

        Michael DD4MS

        Kommentar


        • #5
          Da du gerade mit Zeilenumbrüchen haderst, wird dich jahlives Code nicht weiter bringen. Versuch es mal damit:
          PHP-Code:
          $file file_get_contents('datei.txt');
          // $file = "foobar \nfoo<EOH>bar<EOR>\n<EOH>bar\n<EOR>\r\n<EOH><EOR>foo<EOH>\nbar<EOR>";
          preg_match_all('/<EOH>(.*)<EOR>/sU'$file$matches = array()); 
          Aber wie und wo du das in dein Script einbaust, kannst du mal allein rausfinden.

          Kommentar


          • #6
            Hallo onemorenerd,

            so, ich habs eingebaut. Aber jetzt wird der ADIV file nicht mehr erkannt.
            folgende fehler meldung wird ausgegeben:
            File Upload test.adi

            Filename - test.adi
            DX Callsign - 1
            Warning: fgets(): supplied argument is not a valid stream resource in H:\wamp\www\logauswertung\readlog.php on line 592

            Warning: fgets(): supplied argument is not a valid stream resource in H:\wamp\www\logauswertung\readlog.php on line 612

            Error - Unable to upload file: test.adi

            Invalid Cabrillo or ADIF file

            No QSOs loaded

            deinen code habe ich hier eingebaut:

            PHP-Code:
            // Open the log file
                    
            if (!($file fopen ($uploaddir .$_FILES['userfile']['name'], "r+")))//uploaddir added
                    
                    
            die ("Could not open the log file $file\n");
                    
                    
                    
            $file file_get_contents($uploaddir .$_FILES['userfile']['name']);
            // $file = "foobar \nfoo<EOH>bar<EOR>\n<EOH>bar\n<EOR>\r\n<EOH><EOR>foo<EOH>\nbar<EOR>";
            preg_match_all('/<EOH>(.*)<EOR>/sU'$file$matches = array());//    
                    
                    
                    
                    
                    
                        
            //anderungen ende
                    // Read the first line
                    
            $string fgets ($file1024);

                    
            // Check that it is a Cabrillo File
                    
            if (stristr($string"START-OF-LOG:"))
                    {
                        
            // Process Cabrillo file
                        
            processCabrilloFile ($file,&$qso_count$connection$dxcallsign);

                        
            $file_type "CABRILLO";
                    }
                    
            // Check if it is an ADIF file
                    
            elseif (stristr($string"<EOH>") || stristr($string,"<CALL"))
                    {
                        
            // Process ADIF file
                        
            processADIFFile ($file,&$qso_count$connection,$string$dxcallsign);

                        
            $file_type "ADIF";
                    }
                    else
                    {
                        while ((
            $string fgets ($file1024)) && !$valid_file)
                        {
                            if (
            stristr($string"<EOH>") || stristr($string,"<CALL"))
                            {
                                
            $valid_file 1;
                                
            processADIFFile ($file,&$qso_count$connection,$string$dxcallsign);
                                
            $file_type "ADIF";
                            }
                        }

                        
            // No Cabrillo or ADFI file found - exit with an error
                        
            if (!$valid_file)
                        {
                            echo 
            "<P>Error - Unable to upload file: $browser_name\n";
                            echo 
            "<P>Invalid Cabrillo or ADIF file\n";
                            echo 
            "<P>No QSOs loaded\n";
                            echo 
            '<p><A HREF=\"http://localhost/logauswertung/upload.php">Return to Log Upload Page</A>';
                            die();
                        }
                    } 
            ich verzweifle hier.

            Der Inhalt der datei sieht so aus:

            ADIF Export from SWISSLOG for Windows Version 5.2 Cka
            Date : 15.01.2006 10:56:43
            Log Owner : DD4MS
            http://www.Informatix.li


            <EOH>
            <CALL:5:C>DD4WZ <EQ_CALL:5:C>DD4WZ <DXCC:3:C>230 <NAME:5:C>Mario <YEAR:4:C>2006 <MONTH:2:C>01 <DAY:2:C>07
            <QSO_DATE:8>20060107 <TIME_ON:4:T>2350 <TIME_OFF:4:T>2332 <BAND:3:C>80m <MODE:3:C>SSB <QSL_RCVD:1:C>Z1115778477
            <QSL_SENT:1:C>N <RST_SENT:3:C>59+ <STX:1:C>0 <RST_RCVD:2:C>59 <SRX:1:C>2 <QTH:10:C>Mommenheim <GRIDSQUARE:6:C>JN49DV
            <CQZ:2:C>14 <QSL_ACTION:6:C>senden <FREQ:6:C> 3.737 <MY_QTH:5:C>Worms <CONTEST_ID:14:C>RLP-Woche 2006 <NAME:5:C>Mario
            <MY_OPERATOR:7:C>Michael <MY_CALL:5:C>DD4MS <P_SUB_REGION:3:C>Z77 <L_DISTANZ:2:C>28 <ANT_AZ:6:C>347,88 <P_LATITUDE:4:C>49,9
            <P_LONGITUDE:4:C>8,29 <P_TIMEDIFF:1:C>1 <ITUZ:2:C>28 <P_WAE:2:C>DL <PFX:3:C>DD4 <MY_STATION:8:C>OV Worms
            <P_QTHNAME:7:C>HomeQTH <L_QSONR:4:C>4499 <CONT:2:C>EU <EOR>
            Zuletzt geändert von dd4ms; 17.01.2006, 18:34.
            mfg

            Michael DD4MS

            Kommentar


            • #7
              Tja dir mangelts leider an PHP-Grundlagen.

              Vergleiche http://php.net/file_get_contents
              mit http://php.net/fopen und http://php.net/fgets ...

              Kommentar


              • #8
                Hallo onemorenerd,

                Jo, dann werde ich mich wieder mal mit Grundlagen beschäftigen und mir selbst helfen müssen.

                Die drei befehle hatte ich schon vorher in der PHP Reverenz nachgesehen.

                Danke für die konstruktive Hilfe.
                mfg

                Michael DD4MS

                Kommentar

                Lädt...
                X