SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd like to assign the results of an include() to a variable.

    $foo = include("bar.inc"); obviously doesn't work. I want to this because I require output to be stored in a variable before being echo'ed.

    Thanks again guys.

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "include" just include the file into the current script.
    To save the content into a variable, use fopen/fread
    Here is a small function I have to do that operation:
    Code:
    function getFile($file)
    if (!$filehandle = fopen($file,"r")) 
    {die("Couldn't open the file: $file");}
    else
    { $output = fread($filehandle,filesize($file));
      fclose($filehandle);
      return $output;
    }
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  3. #3
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Darn... I was hoping there was some function or I was unaware of that would make it simple!

    Thanks again Son.


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
  •