Search code examples
phpreadfile

readfile returns additional digit


I am PHP beginner. I am trying to readfile that is saved on a local machine. I have connection, I can read the file but PHP keeps providing with additional digit.

This is my code

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

On the other side the file is very simple it contains only number "10". So the output should be just number 10, but I keep getting 10 3.

This is the output on web interface:

enter image description here

This is the file I am trying to read:

enter image description here


Solution

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

    readfile() automatically echos the file's contents, so you don't need to use echo.

    readfile() also returns an int and that's the 3 you are seeing.

    Change your code to this.

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