Loading all the data of a page into a variable.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bigoxygen@gmail.com

    #1

    Loading all the data of a page into a variable.

    Hi.

    I was wondering how you would go about emulating

    header('Content-Type: application/csv');
    header('Content-Disposition: attachment; filename=' . 'test' . '.csv');


    but instead of getting a file...I would like to load all the data into
    a variable.
    Is this possible?

  • NC

    #2
    Re: Loading all the data of a page into a variable.

    bigoxygen@gmail .com wrote:[color=blue]
    >
    > I was wondering how you would go about emulating
    >
    > header('Content-Type: application/csv');
    > header('Content-Disposition: attachment; filename=test.c sv');
    >
    > but instead of getting a file...I would like to load all the data
    > into a variable. Is this possible?[/color]

    Please clarify your question. Are you trying to generate a file
    or retrieve one? In case you are retrieving, the problem is
    solved very easily:

    $data = file_get_conten ts('test.csv');

    If you have allow_url_fopen enabled, this approach can be used
    on remote files as well.

    Cheers,
    NC

    Comment

    • montgomery.matt@gmail.com

      #3
      Re: Loading all the data of a page into a variable.

      You can also shove the file into an array with the file() function:


      so..

      $file = file('test.csv' );
      foreach($file as $line=>$content ) {
      echo $content;
      }

      Comment

      Working...