1--TEST-- 2fread & fwrite - Test reading and writing using a single resource 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--FILE-- 6<?php 7 8/* 9 * Function is implemented in ext/standard/file.c 10 */ 11 12$outputfile = __FILE__.".tmp"; 13 14echo "--- testing rw moving about the file ---\n"; 15$h = fopen($outputfile, 'wb+'); 16$out1 = "The 1st prrt"; 17$out2 = " part of the ttxt"; 18$out3 = "text"; 19fwrite($h, $out1); 20fseek($h, 0, SEEK_SET); 21echo "start:".fread($h, strlen($out1) - 5). "\n"; 22fwrite($h, $out2); 23echo "at end:".fread($h,100)."\n"; 24var_dump(feof($h)); 25fseek($h, -4, SEEK_CUR); 26fwrite($h, $out3); 27fseek($h, 0, SEEK_SET); 28echo "final:".fread($h, 100)."\n"; 29fclose($h); 30 31echo "--- testing eof ---\n"; 32$h = fopen($outputfile, 'ab+'); 33fread($h,1024); 34var_dump(feof($h)); 35fread($h,1); 36var_dump(feof($h)); 37$out = "extra"; 38fwrite($h, $out); 39var_dump(feof($h)); 40fread($h,1); 41var_dump(feof($h)); 42fseek($h, -strlen($out) + 1, SEEK_CUR); 43echo "last bytes: ".fread($h, strlen($out))."\n"; 44fclose($h); 45 46unlink($outputfile); 47 48echo "Done"; 49?> 50--EXPECT-- 51--- testing rw moving about the file --- 52start:The 1st 53at end: 54bool(true) 55final:The 1st part of the text 56--- testing eof --- 57bool(true) 58bool(true) 59bool(true) 60bool(true) 61last bytes: xtra 62Done 63