SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    How do you assign all the contents in a file to a variable?

    thanks
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if ($file = fopen($filename, "r")) { 
       $contents = fread($file,filesize($filename)); 
       fclose($file); 
    } else { /* file doesn't exist */ }
    PS this is not my code. I found it at:
    http://www.phpbuilder.com/mail/php3-...99805/1377.php
    But it looks right

  3. #3
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!

    How do you print someting onto a file while overwirting everything else?

    Thanks for your help!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $fp = fopen("filetowriteto", "w");
    fwrite($fp, $data);
    fclose($fp);



    the w arg in the fopen statement can take many forms the most common are
    w - open a file for writing(wipes out old data)
    a - open a file for appending(appends data onto exisintg)
    r - open a file for reading
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm....
    How do you print, for example
    0|0
    ?

    fwrite( $str, $str2);
    ?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  6. #6
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay.
    thanks I get it now

    was wondering whats the first variable for fwrite was for..hehez

    thnaks~
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $data = "0|0";

    $fp = fopen("filetowriteto", "w");
    fwrite($fp, $data);
    fclose($fp);
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

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