Return to sprintf_variation17.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 - string 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() : string formats with resource values ***\n"; 11: 12: // resource type variable 13: $fp = fopen (__FILE__, "r"); 14: $dfp = opendir ( dirname(__FILE__) ); 15: 16: // array of resource values 17: $resource_values = array ( 18: $fp, 19: $dfp 20: ); 21: 22: // array of string formats 23: $string_formats = array( 24: "%s", "%hs", "%ls", 25: "%Ls"," %s", "%s ", 26: "\t%s", "\n%s", "%4s", 27: "%30s", "%[a-zA-Z0-9]", "%*s" 28: ); 29: 30: $count = 1; 31: foreach($resource_values as $resource_value) { 32: echo "\n-- Iteration $count --\n"; 33: 34: foreach($string_formats as $format) { 35: var_dump( sprintf($format, $resource_value) ); 36: } 37: $count++; 38: }; 39: 40: // closing the resources 41: fclose($fp); 42: closedir($dfp); 43: 44: echo "Done"; 45: ?> 46: --EXPECTF-- 47: *** Testing sprintf() : string formats with resource values *** 48: 49: -- Iteration 1 -- 50: string(%d) "Resource id #%d" 51: string(1) "s" 52: string(%d) "Resource id #%d" 53: string(1) "s" 54: string(%d) " Resource id #%d" 55: string(%d) "Resource id #%d " 56: string(%d) " Resource id #%d" 57: string(%d) " 58: Resource id #%d" 59: string(%d) "Resource id #%d" 60: string(30) "%sResource id #%d" 61: string(10) "a-zA-Z0-9]" 62: string(1) "s" 63: 64: -- Iteration 2 -- 65: string(%d) "Resource id #%d" 66: string(1) "s" 67: string(%d) "Resource id #%d" 68: string(1) "s" 69: string(%d) " Resource id #%d" 70: string(%d) "Resource id #%d " 71: string(%d) " Resource id #%d" 72: string(%d) " 73: Resource id #%d" 74: string(%d) "Resource id #%d" 75: string(30) "%sResource id #%d" 76: string(10) "a-zA-Z0-9]" 77: string(1) "s" 78: Done