0

嘿,我在这里有一个反文本,我需要知道如何计算总数这是我的信息

$filename = "data.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, 文件大小($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;

我没有得到好的结果

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 回答