如何从计数器文本中计算总数

嘿,我在这里有一个反文本,我需要知道如何计算总数这是我的信息 $ filename =“data.txt”; $ handle = fopen($ filename,“r”); $ contents = fread($ handle,filesize($ filename)); $ expode = explode(“ n”,$ contents); / ** 产量 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 * / 我需要通过爆炸“ n”计算总数,所以我将输出12288需要了解如何做到这一点我做了这个 foreach($ expode as $ v) {     $ total = $ total + $ v;
echo $total;
} 我没有得到好的结果     
已邀请:
<?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');

?>
    

要回复问题请先登录注册