$eof + 1) { fseek($fp, $eof + 1); $ZERO = "\0\0\0\0"; for($i = $eof + 1; $i < $ix; $i++) { fwrite($fp, $ZERO); } $eof = $ix; } fseek($fp, recno($ix)); fwrite($fp, $buf); } function test_write() { $fp = fopen(FNM, 'r+b'); test_write_one($fp, 3, 'CCCC'); test_write_one($fp, 2, 'BBBB'); test_write_one($fp, 1, 'AAAA'); fclose($fp); } function test_read_sequential() { $fp = fopen(FNM, 'rb'); while(true) { $buf = fread($fp, 4); $len = strlen($buf); if($len <= 0) { break; } echo "|$buf| $len\r\n"; } fclose($fp); } function test_read_random_one($fp, $ix) { fseek($fp, recno($ix)); $buf = fread($fp, RECSIZ); $len = strlen($buf); echo "|$buf| $len\r\n"; } function test_read_random() { $fp = fopen(FNM, 'rb'); test_read_random_one($fp, 3); test_read_random_one($fp, 2); test_read_random_one($fp, 1); fclose($fp); } echo "PHP seek\r\n"; test_write(); test_read_sequential(); test_read_random(); ?>