SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast vaiod's Avatar
    Join Date
    Jan 2001
    Location
    Chandler, Arizona
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Storing PHP results to a variable

    I am trying to store the results of some php to a variable but having no luck with it. The concept is similar to include but rather then output it where the include is I want all of it stored to a variable.

    if ($myvar == TRUE) {
    $this_feature = include('this/file');
    }

    This way I can echo the contents of that variable later in the script where I need it.

    Any ideas of how to do this?

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    If you want the contents in your file to be executed, then do like this:

    PHP Code:
    if( $myvar == true )
    {
      
    ob_start();
      include 
    'this/file';
      
    $this_feature ob_get_contents();
      
    ob_end_clean();

    If you just want the content from the file, do like this:

    PHP Code:
    if( $myvar == true )
    {
      
    $this_feature file_get_contents('this/file');

    Yours, Erik.
    Last edited by lilleman; Nov 29, 2004 at 13:24. Reason: Corrected a misspelling.

  3. #3
    SitePoint Enthusiast vaiod's Avatar
    Join Date
    Jan 2001
    Location
    Chandler, Arizona
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Couldn't have been easier... Thanks so much Erik.


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
  •