while (!feof($thisconnection)){ $line = stream_get_contents($this->connection); if (eregi('',$line)){ // is a completed block of xml $buf .= $line; return $buf; } $buf .= $line; if (eregi('',$line)){ // is a new block of xml $buf = $line; $return $buf; } }