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.
精彩评论