Click to See Complete Forum and Search --> : [RESOLVED] Silly problem..
|2eM!x
Sep 17th, 2005, 06:25 PM
Say i wanted to code my script shorter, like so:
<?php
$handle = fopen('mytxt.txt', 'r');
$contents = (@fread($handle,filesize('mytxt.txt')))++;
fclose($handle);
$handle = fopen('mytxt.txt','w');
fwrite($handle,$contents);
fclose($handle);
echo $contents;
?>
instead of doing $contents++
why does that return a parse error? its the same exact thing i think
k1ll3rdr4g0n
Sep 18th, 2005, 12:05 AM
A. Why would you have a add a one to the variable?
B. You don't loop when your reading a file, as PHP reads the whole file at once.
visualAd
Sep 18th, 2005, 03:45 AM
The reason it doesn't work i becuase you are trying to incement a constant. It like saying:
1++
Which won't work becuase the value of one is a constant. The ++ operator increments the value by one and assigns it to that variable.
You can however use this, with the same effect:
$contents++ = (@fread($handle,filesize('mytxt.txt')));
Because you have put ++ at the end of $contents, it will not increment the value until the right part of the expression has been evaluated and asigned to $contents.
|2eM!x
Sep 18th, 2005, 02:57 PM
That still doesnt work, gives me parse errors also :confused:
<?php
$filename = 'Users.txt';
$handle = fopen($filename,'r+');
$contents++ = (@fread($handle,filesize($filename)));
fwrite($handle,$contents);
echo $contents;
fclose($handle);
?>
php always baffles me at its wonderfully bad way of describing errors
visualAd
Sep 18th, 2005, 04:06 PM
You'll have to do it as two lines. Sorry :blush:
$contents = (@fread($handle,filesize($filename)));
++$contents;
|2eM!x
Sep 18th, 2005, 04:14 PM
Thanks visualad
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.