Return to fread_fwrite_basic.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: fread & fwrite - Test reading and writing using a single resource 3: --CREDITS-- 4: Dave Kelsey <d_kelsey@uk.ibm.com> 5: --FILE-- 6: <?php 7: 8: /* 9: * proto int fwrite(resource fp, string str [, int length]) 10: * Function is implemented in ext/standard/file.c 11: */ 12: 13: /* 14: Prototype: string fread ( resource $handle [, int $length] ); 15: Description: reads up to length bytes from the file pointer referenced by handle. 16: Reading stops when up to length bytes have been read, EOF (end of file) is 17: reached, (for network streams) when a packet becomes available, or (after 18: opening userspace stream) when 8192 bytes have been read whichever comes first. 19: */ 20: 21: 22: $outputfile = __FILE__.".tmp"; 23: 24: echo "--- testing rw moving about the file ---\n"; 25: $h = fopen($outputfile, 'wb+'); 26: $out1 = "The 1st prrt"; 27: $out2 = " part of the ttxt"; 28: $out3 = "text"; 29: fwrite($h, $out1); 30: fseek($h, 0, SEEK_SET); 31: echo "start:".fread($h, strlen($out1) - 5). "\n"; 32: fwrite($h, $out2); 33: echo "at end:".fread($h,100)."\n"; 34: var_dump(feof($h)); 35: fseek($h, -4, SEEK_CUR); 36: fwrite($h, $out3); 37: fseek($h, 0, SEEK_SET); 38: echo "final:".fread($h, 100)."\n"; 39: fclose($h); 40: 41: echo "--- testing eof ---\n"; 42: $h = fopen($outputfile, 'ab+'); 43: fread($h,1024); 44: var_dump(feof($h)); 45: fread($h,1); 46: var_dump(feof($h)); 47: $out = "extra"; 48: fwrite($h, $out); 49: var_dump(feof($h)); 50: fread($h,1); 51: var_dump(feof($h)); 52: fseek($h, -strlen($out) + 1, SEEK_CUR); 53: echo "last bytes: ".fread($h, strlen($out))."\n"; 54: fclose($h); 55: 56: unlink($outputfile); 57: 58: echo "Done"; 59: ?> 60: --EXPECT-- 61: --- testing rw moving about the file --- 62: start:The 1st 63: at end: 64: bool(true) 65: final:The 1st part of the text 66: --- testing eof --- 67: bool(true) 68: bool(true) 69: bool(true) 70: bool(true) 71: last bytes: xtra 72: Done