filehandle write to variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • onlineviewer

    filehandle write to variable

    Hello All,

    Can someone help me out with how to go about printing to a variable
    rather than to a file using filehandles. Below i have it in perl, how
    do i
    get this going in php. Thanks in advance...

    $string = '' ";
    open $writeto, '>>', \$string;

    foreach my $file(@array){
    print $writeto $file;
    }

  • Erwin Moller

    #2
    Re: filehandle write to variable

    onlineviewer wrote:
    Hello All,
    >
    Can someone help me out with how to go about printing to a variable
    rather than to a file using filehandles. Below i have it in perl, how
    do i
    get this going in php. Thanks in advance...
    >
    $string = '' ";
    open $writeto, '>>', \$string;
    >
    foreach my $file(@array){
    print $writeto $file;
    }
    Hi,

    What is 'printing to a variable' ?
    Putting content into a variable?

    If so, that is simple:
    $myVar = "Hello World";
    // and add more:
    $myVar .= "\nNext line\n\nBye!";

    If that doesn't help, please be more clearly about what it is you need.

    Regards,
    Erwin Moller


    Comment

    • Rik

      #3
      Re: filehandle write to variable

      On Fri, 22 Jun 2007 03:46:31 +0200, onlineviewer <lancerset@gmai l.com
      wrote:
      Hello All,
      >
      Can someone help me out with how to go about printing to a variable
      rather than to a file using filehandles. Below i have it in perl, how
      do i
      get this going in php. Thanks in advance...
      >
      $string = '' ";
      open $writeto, '>>', \$string;
      >
      foreach my $file(@array){
      print $writeto $file;
      }
      >
      Why not simply concate?

      $string = '';
      foreach($array as $item){
      $string .= $item;
      }

      If you want to write to a variable using filehandles it becomes quite
      different, you'd have to register a stream wrapper to it, check out


      --
      Rik Wasmus

      Comment

      • gosha bine

        #4
        Re: filehandle write to variable

        On 22.06.2007 03:46 onlineviewer wrote:
        Hello All,
        >
        Can someone help me out with how to go about printing to a variable
        rather than to a file using filehandles. Below i have it in perl, how
        do i
        get this going in php. Thanks in advance...
        >
        $string = '' ";
        open $writeto, '>>', \$string;
        >
        foreach my $file(@array){
        print $writeto $file;
        }
        >
        Check out output buffering functions:

        ob_start();

        print "whatever";
        print "something else";

        $output = ob_get_clean();

        Exactly the same functionality as in perl can be achieved using stream
        wrappers. See example here:




        --
        gosha bine

        extended php parser ~ http://code.google.com/p/pihipi
        blok ~ http://www.tagarga.com/blok

        Comment

        Working...