views:

40

answers:

1

Hello! Currently I'm making data parser via Telnet connection using PHP. I've encountered problem: I need to put pointer in a stream to the certain place(not to the end of data), but using of fseek() function is impossible with streams. Tell me, please, how can I solve this problem?

+2  A: 

This function should move your stream cursor to the desired place:

function moveStreamCursorTo(&$fp, $offset)
{
    for ($i = 0; $i < $offset; $i++)
        fgetc($fp);
}

// Use like this:
$curPos = 459;
$desiredPos = 1345;

moveStreamCursorTo($yourStream, $desiredPos - $curPos);

Please test this and report your results.

Franz
Thank you for rapid reply.Your function works perfectly with telnet.But I've just found, that I can use stream_get_line() function for solution, because it allows to separate data by the specified symbol. So this function is more appropriate in this case. However, thank you very much for help.P.S. Sorry for my English, I'm not native speaker.
Alex
That's fine. And so is your English ;)
Franz