Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16
  1. #11
    Join Date
    Jun 2008
    Location
    Manchester
    Posts
    766
    Tokens
    0

    Default

    Quote Originally Posted by Jam-ez View Post
    So what would I do if I wanted to write new data over a file, but keep the old data. You would say append, but that's the end of the file, where as I want the beginning of the file.
    I don't understand what you're trying to say. Writing data over a file keeping the old data? That's not writing over it.

    Do you mean add data to the start of the file?
    PHP Code:
    $file fopen("genchat.php""r+");
    $data "what you want to be added to the start of the file";
    fwrite($file$data);
    fclose($file); 

  2. #12

    Default

    Quote Originally Posted by Jxhn View Post
    I don't understand what you're trying to say. Writing data over a file keeping the old data? That's not writing over it.

    Do you mean add data to the start of the file?
    PHP Code:
    $file fopen("genchat.php""r+");
    $data "what you want to be added to the start of the file";
    fwrite($file$data);
    fclose($file); 
    Would that keep the data already there as well?

  3. #13
    Join Date
    Jun 2008
    Location
    Manchester
    Posts
    766
    Tokens
    0

    Default

    Quote Originally Posted by Jam-ez View Post
    Would that keep the data already there as well?
    I thought it would, but aparantly not.
    Try this:
    PHP Code:
    $filename "genchat.php";
    $data "stufflololol";
    $data .= file_get_contents($filename);
    $file fopen($filename"w");
    fwrite($file$data);
    fclose($file); 
    Doesn't seem like a very good way to do it, but oh well.

  4. #14
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Would be "r+" if you want to write data at the beginning and keep the rest of the data intack.

    If you want to end data to the end of the file "a+"

    You can read the data with these flags as well.
    Hi, names James. I am a web developer.

  5. #15

    Default

    Quote Originally Posted by Jxhn View Post
    I thought it would, but aparantly not.
    Try this:
    PHP Code:
    $filename "genchat.php";
    $data "stufflololol";
    $data .= file_get_contents($filename);
    $file fopen($filename"w");
    fwrite($file$data);
    fclose($file); 
    Doesn't seem like a very good way to do it, but oh well.
    Worked a charm, thanks.

  6. #16
    Join Date
    Jun 2008
    Location
    Manchester
    Posts
    766
    Tokens
    0

    Default

    Quote Originally Posted by Protege View Post
    Would be "r+" if you want to write data at the beginning and keep the rest of the data intack.

    If you want to end data to the end of the file "a+"

    You can read the data with these flags as well.
    That's what I thought, but r+ overwrites it aswell.

Page 2 of 2 FirstFirst 12

Posting Permissions

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