Click to See Complete Forum and Search --> : Text Database


insane
10-16-2005, 05:47 AM
How do i open .txt files and change them?

-Insane

rincewind456
10-16-2005, 06:07 AM
fopen

insane
10-16-2005, 06:10 AM
$bla = fopen('filename.txt'); ??
and then how do i save changes?
fsave?
fset?
fchange?

rincewind456
10-16-2005, 06:14 AM
http://uk2.php.net/manual/en/function.fopen.php

Far to much there for me to rehash in this thread.

insane
10-16-2005, 06:41 AM
? i don't really get it. when i try to echo the file it always ouputs "Resource id #2"
how do i get it to read the actual content? and/or edit it?

rincewind456
10-16-2005, 06:48 AM
? i don't really get it. when i try to echo the file it always ouputs "Resource id #2"
how do i get it to read the actual content? and/or edit it?

From the manual : <?php $hi = fopen("myfile.txt","r");
$text = fread($hi,filesize("myfile.txt")); fclose($hi); ?>
So '$text' would = contents of file, or use this alternative function;
<?php $hi = file("myfile.txt"); print_r($hi); ?>
'file' reads the contents of your file, and will store it in the '$hi' variable as an array of lines.
'print_r' will simply print this array in an easy-to-read way.

Also take a look here for a good tutorial: http://www.zend.com/zend/tut/tutorial-jenkins2.php

bokeh
10-16-2005, 09:21 AM
If you want to echo the contents of a file you just do this:
print file_get_contents('file/path/filename.ext');