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

发布于 2024-09-02 17:22:00 字数 431 浏览 9 评论 0原文

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

$filename = "data.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, 文件大小($filename)); $expode = 爆炸("\n",$contents);

/** 输出 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 1024 */ 我需要通过爆炸“\n”来计算总数,所以我将输出 12288 需要了解如何做到这一点我已经完成了这个

foreach ($expode as $v) { $总计 = $总计 + $v;

echo $total;

} 我没有得到好的结果

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
1024
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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

古镇旧梦 2024-09-09 17:22:00
<?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');

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

?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文