Jump to content

[SOLVED] finding the end of a line in a text file...


Yammyguy

Recommended Posts

I'm wondering if anyone can help me with some code.  It's probably fairly straight forward.

 

I'm able to upload a text file, explode it and enter it into a database.  What I would like to do is determine the number of entries each line contains...  For example I have a tabular separated file, but I don't know how many entries each line contains.  I would like to know how many there are before the carriage return/line return.

 

As of now, I've always known the number of entries, so I'd pre-declare the variables in anticipation for the upload.  Here's my code:

$target_file = basename( $_FILES['uploadedfile']['name']);
$target_path = "/var/www/lakeland/uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ".  basename( $_FILES['uploadedfile']['name'])." has been uploaded";

// Read the file into an array
$demand = file($target_path);

// Remove initial header which is also filename.
$file_name = array_shift($demand);

        foreach ($demand as $entry) {
             // Break each line of the file into independent parts
     list($date, $time, $KW, $kVAr, $kVA, $PF) = explode("\t", $entry);
         }

 

I've looked everywhere online - and can't find any code reference for counting the number of entries on each line. 

 

Thanks very much in advance!!!

~C.

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.