Re: Pulling Data From a Loop

From: Date: Mon, 26 Jun 2000 07:16:25 +0000
Subject: Re: Pulling Data From a Loop
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-3076@lists.php.net to get a copy of this message
On 26 Jun, Mike Gifford wrote: > Hello, > > I've constructed a script that outputs exactly what I want, however, I > need to capture the output as a variable, how do I do this. > > I thought that if instead of using echo $buffer to output the data to > the screen, I could use an array of some sort to capture the information > into a variable $rdf2a[$i] = $buffer; > > I would like to be able to echo $rdf2a[] outside of the loop and get the > same results that I did when I simply echo $buffer inside of the loop. > > Unfortunately, I haven't been able to figure out how to make this simple > function work. > > <? > $page3 = "wtowatch3.txt"; > $fd = fopen("$page3", "r"); > $i=1; > while ($buffer = fgets($fd, 4096)) { >  > $buffer = eregi_replace( > "(<link>.*</item>)(<title>.*</title>)", "\\2 > \n \\1 \n", $buffer); > $buffer = eregi_replace( "</link>", "</link>\n", $buffer ); > echo $buffer; > // $rdf2a[$i] = $buffer; > i++; > } > fclose($fd); > > // echo $rdf2a[] > ?> > > Thanks. > > Mike Couple of things you could try; using list and each to loop through the array $rdf2a and echo the individual elements using implode to put the contents of the array in a string which you can then echo appending $buffer to itself/another variable which you can then echo outside the loop Cheers -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#3076) next »