0

ねえ、私はここにカウンターテキストを持っています、そして私はこれが私の情報である合計を計算する方法を知る必要があります

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

/**出力102410241024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 */「\n」を展開して合計を計算する必要があるので、出力12288これを行う方法を理解する必要がありますこれを実行しました

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

echo $total;

}これでは良い結果が得られませんでした

4

1 に答える 1

0
<?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');

?>
于 2010-05-22T02:54:18.413 に答える