Jump to content

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.

Thanks for the info, but it turns out that still just counts the total number of keys in the array, not just in the one line.

 

I've uploaded a file that had 1728 keys and I've already used the "count()" function...

 

Back to square one. :(

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.