roime Posted November 22, 2008 Share Posted November 22, 2008 Hi all, I have a problem on php coding. I have a text file that consists of a data like this joe.txt; 12 34 32 34 21 23 By using php, i try to split the data into a separated group that consists 2 values such a format like below; group 1; 12 34 group 2; 32 34 group 3; 21 23 I've successfully writes a script to read all of the values, display them and sum all of them..But i still refused to split them and sum all of them based on their groups..If u guys have an idea then please help me... Scripts that i had; <?php $myFile = "joe.txt"; $handle = fopen($myFile, 'r'); while (!feof($handle)) { $data = fgets($handle, 512); echo $data; echo "<br>"; $total += $data; } fclose($handle); $lines = count(file($myFile)); echo "There are $lines lines in $myFile"; echo "<br>"; echo "Total value was : $total"; ?> Quote Link to comment 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.