1--TEST-- 2Test fseek() function : variation functionality beyond file boundaries 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--FILE-- 6<?php 7echo "*** Testing fseek() : variation - beyond file boundaries ***\n"; 8 9$outputfile = __FILE__.".tmp"; 10 11$h = fopen($outputfile, "wb+"); 12for ($i = 1; $i < 10; $i++) { 13 fwrite($h, chr(0x30 + $i)); 14} 15 16echo "--- fseek beyond start of file ---\n"; 17var_dump(fseek($h, -4, SEEK_SET)); 18echo "after -4 seek: ".bin2hex(fread($h,1))."\n"; 19var_dump(fseek($h, -1, SEEK_CUR)); 20echo "after seek back 1: ".bin2hex(fread($h,1))."\n"; 21var_dump(fseek($h, -20, SEEK_CUR)); 22echo "after seek back 20: ".bin2hex(fread($h,1))."\n"; 23 24echo "--- fseek beyond end of file ---\n"; 25var_dump(fseek($h, 16, SEEK_SET)); 26fwrite($h, "end"); 27fseek($h ,0, SEEK_SET); 28$data = fread($h, 4096); 29echo bin2hex($data)."\n"; 30 31fclose($h); 32unlink($outputfile); 33 34echo "Done"; 35?> 36--EXPECT-- 37*** Testing fseek() : variation - beyond file boundaries *** 38--- fseek beyond start of file --- 39int(-1) 40after -4 seek: 41int(0) 42after seek back 1: 39 43int(-1) 44after seek back 20: 45--- fseek beyond end of file --- 46int(0) 4731323334353637383900000000000000656e64 48Done 49