Hi,
In your code *if ($temp == "4 ")* will always return false, and so no
replcament occurs.
$temp will contain the new line chars so a trim() is necessary before
comparison.
Try this modified code and you will find it working perfectly fine. So
its not the mode of file but the comparison statement, which is
causing problem.
Cheers...
-- Rahul
[SNIP]
<?
$fp = fopen("content.txt","r+");
while (!feof($fp)) {
$temp=fgets($fp);
if (trim($temp) == "4"){
fseek($fp, strlen($temp)*-1, SEEK_CUR);
fputs($fp,"#\r\n");
}
}
fclose($fp);
?>
[/SNIP]
terra1024@yahoo.com (yawnmoth) wrote in message news:<a0d63404.0312191142.74a21967@posting.google. com>...[color=blue]
> i'm trying to read / write a file, and am having some problems...
>
> here's the php script i'm trying to read / write with:
>
> <?
> $fp = fopen("test","r+");
> while (!feof($fp)) {
> $temp=fgets($fp);
> if ($temp == "4 ")
> fputs($fp,"###");
> }
> fclose($fp);
> ?>
>
> the contents of test are as follows:
>
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 0
>
> now, i would expect 4 to either be replaced by ###'s, or for ###'s to
> be added after 4. however, no such thing happens, and i'm not sure
> why. any ideas? also, if you can only read, or you can only write
> (which is the best explanation i can come up with, atm, for the above
> code not working), then what's the point of having modes that support
> both?[/color]