Page 1 of 1

I need help with file editing

Posted: Mon Apr 21, 2003 12:52 pm
by DraginX
I was just wondering how could I take a file, and if it has text in it, I want to delete that text. Then I want to put in new text in.

(Im making a little MySQL tihngy, with menu tree and I need to edit the menu tree file to display the correct information).

Thank you :)

fopen date escape character regular expression onload php

Posted: Mon Apr 21, 2003 3:13 pm
by phpfreak
hi there,

the below code deletes the contents in the text file and then inserts the date into it.

==============================================
<?php
$first=open_file();
function open_file()
{

$for_date = date("H:i-j/m/y");
$fp = fopen ("c:\\sesha\\info.txt", "w");
//change the file to any text file you want.
//do use the escape character ''' in the windows.
if (!($fp))
{
exit;
}
while (!feof($fp))
{
$line = fread ( $fp, 1024 );
str_replace ('[a-zA-z0-9]+',"",$line);
}


fputs($fp," ");
fputs ($fp,"$for_date|$sh");

fclose ($fp);

}


?>
<body onLoad="<?php echo $first;?>">

===============================================
hope it helped

regards
srinivas

Posted: Mon Apr 21, 2003 3:14 pm
by m3mn0n
Have you looked at the Manual's filesystem functions? fopen and it's associated funcs should help you out. :)

Posted: Mon Apr 21, 2003 11:03 pm
by McGruff
Minor suggestion, change:

$fp = fopen ("c:\\sesha\\info.txt", "w");

to..

$fp = fopen ("c:\\sesha\\info.txt", "wb");


Php Manual:

Note:
The mode may contain the letter 'b'. This is useful only on systems which differentiate between binary and text files (i.e. Windows. It's useless on Unix). If not needed, this will be ignored. You are encouraged to include the 'b' flag in order to make your scripts more portable.