Page 1 of 1

opening and writing to a file

Posted: Mon Apr 17, 2006 5:32 pm
by elecktricity
hello all I need a bit of help with something, basicially I have a file (numbers.txt) it contains the contents:
0
I need numbers.php to read this and put it in a variable
its tried a few things:

Code: Select all

$file1 = fopen('nubers.txt', 'w+');
$file2 = include('numbers.txt');
and a few other but none seem to work, how would I do this?

Posted: Mon Apr 17, 2006 6:00 pm
by printf
You can do it many different ways....

Code: Select all

$var = file_get_contents ( './numbers.txt' );

// or

$var = fread ( fopen ( './numbers.txt', 'rb' ), filesize ( './numbers.txt' ) );
There are other ways to, these are just a few!


pif!

Posted: Mon Apr 17, 2006 6:22 pm
by RobertGonzalez