开发者

How to put pointer in the desired place in a stream using PHP?

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜