|
-
Sep 17th, 2005, 06:25 PM
#1
Thread Starter
Admodistrator
[RESOLVED] Silly problem..
Say i wanted to code my script shorter, like so:
PHP Code:
<?php
$handle = fopen('mytxt.txt', 'r');
$contents = (@fread($handle,filesize('mytxt.txt')))[B][COLOR=DarkOrange]++[/COLOR][/B];
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
-
Sep 18th, 2005, 12:05 AM
#2
Fanatic Member
Re: Silly problem..
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.
-
Sep 18th, 2005, 03:45 AM
#3
Re: Silly problem..
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:
PHP Code:
$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.
-
Sep 18th, 2005, 02:57 PM
#4
Thread Starter
Admodistrator
Re: Silly problem..
That still doesnt work, gives me parse errors also
PHP Code:
<?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
-
Sep 18th, 2005, 04:06 PM
#5
Re: Silly problem..
You'll have to do it as two lines. Sorry 
PHP Code:
$contents = (@fread($handle,filesize($filename)));
++$contents;
-
Sep 18th, 2005, 04:14 PM
#6
Thread Starter
Admodistrator
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|