You are here: Re: fopen and r+ problem « All PHP « IT news, forums, messages
Re: fopen and r+ problem

Posted by Tom on 09/12/07 18:04

On Wed, 12 Sep 2007 18:24:06 +0200, s1m0n wrote...
>
>Hi everybody,
>
>I would like to write a simple code to add some text at the begining of
>a file without erase the other data.
>
>in my file:
>
>news4
>news3
>news2
>news1
>
>if I want to add the text "news5!", the file will look like this:
>
>news5!
>news4
>news3
>news2
>news1
>
>So I wrote this:
>
><?php
>
>if (isset($HTTP_POST_VARS['go'])) {
>
> $content = "\r\n" . $HTTP_POST_VARS['news'] . "<br />";
>
> $write = fopen('news.ini', 'r+');
>
> fwrite($write, $content);
>
> fclose($write);
>
>?>
>
>
><form action="" method="post">
><input type="text" name="news" size="28" /><input type="submit"
>name="go" value="Go" />
></form>
>
><?php
>
>} else {
>
>?>
>
><form action="" method="post">
><input type="text" name="news" size="28" /><input type="submit"
>name="go" value="Go" />
></form>
>
><?php
>
>}
>
>?>
>
>But this code doesn't work, everything is erase in my file, no new line
>appears...
>Could you please help me ?
>Thank you, and hope my english is understandable.
>

I think if you are writing to a file, it either starts as a new file or could
set your commands to append to the end of an existing one.

If you are trying to add to the beginning, you probably need to juggle a few
files temporarily. Maybe start a new file with the content you want on top, then
append the original content to the end of that new file. You would need to
juggle file names around a bit.

Tom
--
Newsguy.com - Unlimited Accounts
Now with 32 concurrent connections

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация