Yammyguy Posted March 5, 2009 Share Posted March 5, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/148024-solved-finding-the-end-of-a-line-in-a-text-file/ Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 $tmp = explode("\t", $something); $number_of_elements = count($tmp); Quote Link to comment https://forums.phpfreaks.com/topic/148024-solved-finding-the-end-of-a-line-in-a-text-file/#findComment-776953 Share on other sites More sharing options...
Yammyguy Posted March 5, 2009 Author Share Posted March 5, 2009 Geez, I knew it was straight forward!! Thank you very much for such a quick response! :D Quote Link to comment https://forums.phpfreaks.com/topic/148024-solved-finding-the-end-of-a-line-in-a-text-file/#findComment-776958 Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 No problem ;p. Quote Link to comment https://forums.phpfreaks.com/topic/148024-solved-finding-the-end-of-a-line-in-a-text-file/#findComment-776964 Share on other sites More sharing options...
Yammyguy Posted March 5, 2009 Author Share Posted March 5, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/148024-solved-finding-the-end-of-a-line-in-a-text-file/#findComment-776983 Share on other sites More sharing options...
Yammyguy Posted March 5, 2009 Author Share Posted March 5, 2009 Figured out my mistake. Thank you... Quote Link to comment https://forums.phpfreaks.com/topic/148024-solved-finding-the-end-of-a-line-in-a-text-file/#findComment-777015 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.