Posted By

micmath on 10/30/07


Tagged

php5


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

arcturus
vali29
adix


Treat variable as a file


 / Published in: PHP
 

Occasionally you'll have a string and need to pass it to a function that will only take a filehandle (such as fgetcsv). Here's how to create a virtual filehandle in memory.

  1. $value = "Ennie,Meenie,Minie,Mo";
  2. $fh = fopen('php://memory', 'rw');
  3. fwrite($fh, $value);
  4. rewind($fh);
  5. $array = fgetcsv($fh, 1024);
  6. fclose($fh);

Report this snippet  

You need to login to post a comment.