Reputation: 512
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:
This is the file I am trying to read:
Upvotes: 1
Views: 1567
Reputation: 41
Documentation for "readfile" function from PHP.net says :
readfile
Returns the number of bytes read from the file. If an error occurs, FALSE is returned and unless the function was called as @readfile(), an error message is printed.
Source : http://php.net/manual/en/function.readfile.php
If you want to read the contents of a file and get the result as a string use the file_get_contents function.
Documentation for "file_get_contents" function is available here : http://php.net/manual/en/function.file-get-contents.php
Upvotes: 1
Reputation: 5041
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>
Upvotes: 5