Jump to content

How do I use and Gather Information from a Txt file that has been uploaded?


PhotonicCoder

Recommended Posts

Ok Basically I need to know how to do this:

 

 

I upload a txt file that contains this:

 

"MLE ",20,"2057NALL       ","ND ","Amber for 2057 1         ","!Amber for 2057          ",00003.65,00001.02                       
"MLE ",20,"211-2          ","D  ","Dome-Courtesy 10         ","!Dome-Courtesy 1         ",00001.60,00000.61                       

 

How would I get Information from each different line like the below:

 

2057NALL     |   Amber for 2057 1     |     00003.65     |     00001.02        
211-2           |   Dome-Courtesy 10   |     00001.60     |     00000.61        

 

Any help on this subject would be greatly appreciated.

 

PhotonicCoder

Ok here is something:

 

This will get everything 5 spaces in on the line

<?php
fread($fh, 5);
?>

 

And this will get the amount of lines:

 

<?php
$lines = file("upload/" . $_FILES["file"]["name"]);
      
      $lineCount = count($lines);
?>

 

But how do I choose the Individual line and get information from certain parts of the text?

 

PhotonicCoder

 

But how

Your question is pretty ambiguous.  As in, no one really understands the question.

 

<?php
$lines = file("upload/" . $_FILES["file"]["name"]);
echo '<pre>';
for($i = 0; $i < $lineCount; $i++) {
if(empty($lines[$i])) { continue; }
$parts = explode(',',$lines[$i]);
echo str_replace('"','',$parts[2]) . ' | ' . str_replace('"','',$parts[4]) . ' | ' . str_replace(array('"','!'),'',$parts[5]) . ' | ' . $parts[6] . ' | ' . $parts[7] . "\n";
}
echo '</pre>';

 

In it's simplest form.

Unfortunately realized that this was ambiguous, however Thank you so much for this so I can get farther down the road. I will mark this topic solved after I go over it.

 

Thank you again for that jcbones!

 

PhotonicCoder

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.