Return to sprintf_variation5.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test sprintf() function : usage variations - int formats with resource values 3: --FILE-- 4: <?php 5: /* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]]) 6: * Description: Return a formatted string 7: * Source code: ext/standard/formatted_print.c 8: */ 9: 10: echo "*** Testing sprintf() : integer formats with resource values ***\n"; 11: 12: // resource type variable 13: $fp = fopen (__FILE__, "r"); 14: $dfp = opendir ( dirname(__FILE__) ); 15: 16: $fp_copy = $fp; 17: $dfp_copy = $dfp; 18: 19: // array of resource types 20: $resource_types = array ( 21: $fp_copy, 22: $dfp_copy 23: ); 24: 25: // various integer formats 26: $int_formats = array( 27: "%d", "%Ld", " %d", 28: "\t%d", "\n%d", "%4d", 29: "%[0-9]", "%*d" 30: ); 31: 32: $count = 1; 33: foreach($resource_types as $res) { 34: echo "\n-- Iteration $count --\n"; 35: 36: foreach($int_formats as $format) { 37: var_dump( sprintf($format, $res) ); 38: } 39: $count++; 40: }; 41: 42: // closing the resources 43: fclose($fp); 44: closedir($dfp); 45: 46: 47: echo "Done"; 48: ?> 49: --EXPECTF-- 50: *** Testing sprintf() : integer formats with resource values *** 51: 52: -- Iteration 1 -- 53: string(%d) "%d" 54: string(1) "d" 55: string(%d) " %d" 56: string(%d) " %d" 57: string(%d) " 58: %d" 59: string(%d) "%s%d" 60: string(%d) "0-9]" 61: string(1) "d" 62: 63: -- Iteration 2 -- 64: string(%d) "%d" 65: string(1) "d" 66: string(%d) " %d" 67: string(%d) " %d" 68: string(%d) " 69: %d" 70: string(%d) "%s%d" 71: string(%d) "0-9]" 72: string(1) "d" 73: Done