opening and writing to a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

opening and writing to a file

Post 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?
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post 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!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Post Reply