Is there a way to make this:

Ref_701;
CPB 1.RA1;
WS-C4503;
FOX083906BS;
2;
WS-X4013+TS,JAB083907AK;
WS-X4548-GB-RJ45,JAE0844Z5L2;
WS-X4548-GB-RJ45,JAE0844Z5DQ;
;
Ref_704;
CPB 1.RA2;
WS-C4503;
FOX083001XG;
2;
WS-X4013+TS,JAB083906VT;
WS-X4548-GB-RJ45,JAE0843YYK9;
WS-X4548-GB-RJ45,JAE0844Z5N1;
;
Ref_707;
CPB 1.RA3;
WS-C4503;
FOX083001XJ;
2;
WS-X4013+TS,JAB085301VU;
WS-X4548-GB-RJ45,JAE084810G8;
WS-X4548-GB-RJ45,JAE0843Z2TN;
;

and plenty more records....

And change it to:

Ref_701;CPB 1.RA1;WS-C4503;FOX083906BS;2;WS-X4013+TS,JAB083907AK;WS-X4548-GB-RJ45,JAE0844Z5L2;WS-X4548-GB-RJ45,JAE0844Z5DQ;
Ref_704;CPB 1.RA2;WS-C4503;FOX083001XG;2;WS-X4013+TS,JAB083906VT;WS-X4548-GB-RJ45,JAE0843YYK9;WS-X4548-GB-RJ45,JAE0844Z5N1;
Ref_707;CPB 1.RA3;WS-C4503;FOX083001XJ;2;WS-X4013+TS,JAB085301VU;WS-X4548-GB-RJ45,JAE084810G8;WS-X4548-GB-RJ45,JAE0843Z2TN;
;

I don't know where to even begin here.

    I think a regular expression would be the "right" way to do the job, but since complex text processing tends to be more confusing than helpful i'll explain the other way...

    assuming every line starts with the 'Ref_' you can use if to split the lines, then just remove the spaces and put everything together again:

    $string = explode ('Ref_',$string);
    foreach ($string as &$line){
       $string = str_replace ("\n",'',$string);
    }
    $string = join ('Ref_',$string);
    
      $str = explode("Ref_",str_replace("\n","",$str));
      $i = 0;
      while($i < count($str))
      {
      $str[$i] .= "\n";
      $i++
      }
      $str = implode('',$str);
      

      Try that out

        Not having much luck. Here is my code. I'm missing something...

        <?php
        $filename = "inventory.txt";
        $separate = explode('Ref_',$string1); 
        foreach ($separate as &$line){ 
           $combine = str_replace ("\n",'',$separate); 
        } 
        $string = join('Ref_',$combine); 
        
        $csvcontent = $string 
        $handle = fopen("$filename", 'w'); 
        fwrite($handle,$csvcontent); 
        fclose($handle); 
        
        ?>
        (END) 

          I think I'm almost there. I'm having problems imploding or joining though....

          Here's my code:

          <?php
          $filename = "inventory.txt";
          $string1 = file($filename);
          $separate = explode('Ref_',$string1);
          foreach ($separate as $line){
             $combine = str_replace ("\n",'',$line);
          }
          $csvcontent = implode('Ref_',$combine);
          
          $handle = fopen("$filename", 'w');
          fwrite($handle,$csvcontent);
          fclose($handle);
          
          ?>
            Write a Reply...