【问题标题】:Adding the contents of multiple files in php [duplicate]在php中添加多个文件的内容[重复]
【发布时间】:2021-02-24 05:06:35
【问题描述】:

我可以为每个跟踪器添加一个额外的命中计数器,但查看组合数据的次数会更少,因此整体服务器负载会更少。

我正在从多个来源提取数据。一个数字存储在文本中,我希望也能显示总数。

我认为这会奏效。假设值为81411。总数应该是43,但这只会显示8。这是我正在使用的;

<?php echo file_get_contents
("/count/counter1.txt") + 
("/count/counter2.txt") +  
("/count/counter3.txt") ;
?>

任何帮助将不胜感激。我使用+1 添加点击,但相同的逻辑不会添加每个txt 文档的内容。

EDIT 不知道为什么当问题是关于加法时,这被认为已经有了答案,所以不一样。

【问题讨论】:

  • 没有 php 函数允许您使用加号和新的括号集来耦合其他参数。

标签: php


【解决方案1】:
<?php 
echo file_get_contents
("/count/counter1.txt") + 
("/count/counter2.txt") +  
("/count/counter3.txt") ;

此代码接下来会执行:

获取文件/count/counter1.txt 的内容并添加一些("/count/counter2.txt")(不是文件内容!)。

("/count/counter2.txt") 只是一个字符串 "/count/counter2.txt" 转换为数字 0,因为这适用于 + 运算符

你得到:8 + 0 + 0 = 8

对每个文件使用 file_get_contents 函数:

<?php
echo file_get_contents("/count/counter1.txt") + 
file_get_contents("/count/counter2.txt") +  
file_get_contents("/count/counter3.txt") ;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-01
    • 2017-06-24
    • 2016-01-30
    相关资源
    最近更新 更多