Jump to content

print from file


Gatsu
 Share

Recommended Posts

hi, I want to print the content of a text file to my website.on the index.php I have:<td>Player Record: <?php print $record ?></td>and in config.php$record = print_r(file('E:\TheForgottenServer 0.2.6\playersRecord.txt')) ; //Player Recordsee my result at http://90.230.82.9/I want the "254" that the file contains to be printed and not the "Array ( [0] => 254 )" that comes up but on even a totally different spot on the site.Does anybody have a solution for this?

Link to comment
Share on other sites

From php.net"file — Reads entire file into an array"If you are going to have more than one record, you might want to use a database. With arrays to get information from the array, you need to have ['key'], replacing key with either a number or whatever you called it. In this case, you will replace key with 0, as you will see with the result Array([0]=>254).

Link to comment
Share on other sites

You could also just use file_get_contents(), which reads the file into one big string (but with only one value that won't matter). Also, you don't need to "print" or "echo" values into a variable, just assign.

$record = file_get_contents('E:\TheForgottenServer 0.2.6\playersRecord.txt'); //Player Record

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...