代码之家  ›  专栏  ›  技术社区  ›  quant

readfile返回附加数字

  •  1
  • quant  · 技术社区  · 7 年前

    我是PHP初学者。我正在尝试读取保存在本地计算机上的文件。我有连接,我可以读取文件,但PHP不断提供额外的数字。

    这是我的密码

    <html>
        <body>
            <h1>My first PHP page</h1>
            <?php
                echo readfile("/home/pi/test/hx711py/export.txt", "r");
            ?>
        </body>
    </html>
    

    另一方面,文件非常简单,它只包含数字“10”。 所以输出应该是10,但我一直得到10 3。

    这是web界面上的输出:

    enter image description here

    这是我试图读取的文件:

    enter image description here

    2 回复  |  直到 7 年前
        1
  •  4
  •   Funk Forty Niner    7 年前

    http://php.net/manual/en/function.readfile.php

    readfile() 自动回显文件内容,因此您不需要使用 echo

    readfile() 还返回一个int,这就是你看到的3。

    将代码更改为此。

    <html>
    <body>
    <h1>My first PHP page</h1>
    <?php
    readfile("/home/pi/test/hx711py/export.txt", "r");
    ?>
    </body>
    </html>
    
        2
  •  1
  •   vikramj74    7 年前

    PHP中“readfile”函数的文档。net说:


    返回从文件中读取的字节数。如果发生错误,则返回FALSE,除非函数被称为@readfile(),否则将打印错误消息。

    资料来源: http://php.net/manual/en/function.readfile.php


    如果要读取文件内容并将结果作为字符串,请使用file\u get\u contents函数。

    http://php.net/manual/en/function.file-get-contents.php