Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top