Reputation: 566
I wrote a simple single liner PHP program to output contents of a file. The HTML code is:
<form action="output.php">
<input type="submit" value="submit">
</form>
output.php file:
<?php
echo readfile("text.txt");
?>
text.txt file:
hi hello
hexdump of text.txt file:
there is 0000008 in the end but in the utf-8 format i don't think 08 corresponds to the character '8'
But in the browser when i click the submit button the output is:
hi hello8
I don't know where the 8 came from. how can i solve this issue to print "hi hello" not "hi hello8"
Upvotes: 1
Views: 169
Reputation: 33238
readfile()
returns the number of bytes read on success. So in your case the file contains 8 bytes.
readfile()
will output the contents of the file, so I assume your mistake here was to assume that it will return the contents and you need to echo
them yourself, but that is what file_get_contents()
does
Upvotes: 1