Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Replacing string in file problems...

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Replacing string in file problems...

Postby CrustyDOD » Tue Apr 15, 2003 5:58 am

Hi

I have a small problem or big i u will...

i have a file zs.inc and the contents of
the file is just date (ex: 2.2.2003).

now here the code to open that file
and get the contents into string:

$filename = "zs.inc";
$fp = fopen ($filename, "r+");
$read_file = fread($fp, filesize ($filename));
$str_read = $read_file;
$str_date = "$date";
$str_read1 = str_replace($str_read, $str_datum, $str_read);
fputs ($fp, $str_read1);
fclose ($fp);

What's the problem? The problem is that this doesn't
replaces the contents of the file, it appends the
new date a line under the first.

here's the example:

contents of the file, before running code:
2.2.2003

after running the code:
2.2.2003
3.2.2003

I just want to replace the first date (2.2.2003)
with the current date(3.2.2003).

See my problem? Intead of replacing the first date
with the current it appends it self a line under.

How to fox this?

I also tied with fwrite but it's the same s...

help me...

thx
CrustyDOD
New php-forum User
New php-forum User
 
Posts: 13
Joined: Tue Oct 29, 2002 2:58 am

Postby liquedus » Tue Apr 15, 2003 9:06 am

well this may be a barbaric suggestion of sorts but, once you get the date into memory, close the filestream, delete the file, and create a new file with $filename and then write new date to it....
liquedus
php-forum Active User
php-forum Active User
 
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], MrExeqtor and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.