Results 1 to 6 of 6

Thread: [RESOLVED] Silly problem..

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Resolved [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

  2. #2
    Fanatic Member
    Join Date
    Oct 2004
    Posts
    751

    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.
    My Projects: [ Instant Messagener Client/Server ] [ VBPictochat ]

    My Sites:
    [ Datanethost ]
    [ Helpdesk ]

    Remember if my post was helpful then Rate This Post.

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    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

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Silly problem..

    You'll have to do it as two lines. Sorry
    PHP Code:
    $contents = (@fread($handle,filesize($filename)));
    ++
    $contents
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Silly problem..

    Thanks visualad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width