开发者

fread how to Count total from Counter text

hey i have a counter text here and i need to know how to calculate the total this is my information

$filename = "data.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); $expode = explode("\n",$contents);

/** output 1024 1024 1024 1024 1024 10开发者_开发问答24 1024 1024 1024 1024 1024 1024 1024 */ I i need to calculate the total by exploding "\n" so i will output 12288 need to understand how to do this i have done this

foreach ($expode as $v) { $total = $total + $v;

echo $total;

} i did not get good results with this


<?php

    /**
     * @author Saxtor Inc
     * @copyright 2010
     */

    function TotalBytes($definefilename)
    {  
         $isfile     = is_file($definefilename); //define the file name

            if ($isfile == 1) //if the file is true
         {
            $handle   = fopen($definefilename, "r"); //open the file check the information
            $contents = fread($handle, filesize($definefilename)); //define the filesize
            $expode   = explode("\n", $contents); //explode the "\n char"
            $count    = count($expode, COUNT_RECURSIVE); //count how much total
            while ($i <= $count) //count total values

            {
                $totalcount = $totalcount + $expode[$i] . "\n"; //count total values; :D
                $i++;
            }
            return $totalcount; //return total aye it works

        }
        else
        {
            return "Not Found";
        }
    }
    echo TotalBytes('data.txt');

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜