Return to vfprintf_variation7.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test vprintf() function : usage variations - string formats with strings 3: --FILE-- 4: <?php 5: /* Prototype : int vfprintf ( resource $handle , string $format , array $args ) 6: * Description: Write a formatted string to a stream 7: * Source code: ext/standard/formatted_print.c 8: */ 9: 10: /* 11: * Test vfprintf() when different string formats and string values are passed to 12: * the '$format' and '$args' arguments of the function 13: */ 14: 15: echo "*** Testing vfprintf() : string formats with strings ***\n"; 16: 17: 18: // defining different heredoc strings 19: $heredoc_string = <<<EOT 20: This is string defined 21: using heredoc. 22: EOT; 23: 24: /* heredoc string with only numerics */ 25: $heredoc_numeric_string = <<<EOT 26: 123456 3993 27: 4849 string 28: EOT; 29: 30: /* empty heardoc string */ 31: $heredoc_empty_string = <<<EOT 32: EOT; 33: 34: // defining array of string formats 35: $formats = array( 36: "%s", 37: "%+s %-s %S", 38: "%ls %Ls, %4s %-4s", 39: "%10.4s %-10.4s %04s %04.4s", 40: "%'#2s %'2s %'$2s %'_2s", 41: "%% %%s %10 s%", 42: '%3$s %4$s %1$s %2$s' 43: ); 44: 45: // Arrays of string values for the format defined in $format. 46: // Each sub array contains string values which correspond to each format string in $format 47: $args_array = array( 48: array(" "), 49: array("hello\0world", "hello\0", "\0hello"), 50: array("@#$%&*", "@#$%&*", "\x55F", "\001"), 51: array("sunday", 'monday', "tuesday", 'wednesday'), 52: array($heredoc_string, "abcdef", $heredoc_numeric_string, $heredoc_empty_string), 53: array("one", "two", 'three', 'four'), 54: array("three", 'four', 'one', "two") 55: 56: ); 57: 58: /* creating dumping file */ 59: $data_file = dirname(__FILE__) . '/dump.txt'; 60: if (!($fp = fopen($data_file, 'wt'))) 61: return; 62: 63: // looping to test vfprintf() with different string formats from the above $format array 64: // and with string from the above $args_array array 65: $counter = 1; 66: foreach($formats as $format) { 67: fprintf($fp, "\n-- Iteration %d --\n",$counter); 68: vfprintf($fp, $format, $args_array[$counter-1]); 69: $counter++; 70: } 71: 72: fclose($fp); 73: print_r(file_get_contents($data_file)); 74: echo "\n"; 75: 76: unlink($data_file); 77: 78: ?> 79: ===DONE=== 80: --EXPECT-- 81: *** Testing vfprintf() : string formats with strings *** 82: 83: -- Iteration 1 -- 84: 85: -- Iteration 2 -- 86: hello world hello 87: -- Iteration 3 -- 88: @#$%&* s, UF & 89: -- Iteration 4 -- 90: sund mond tuesday wedn 91: -- Iteration 5 -- 92: This is string defined 93: using heredoc. abcdef 123456 3993 94: 4849 string __ 95: -- Iteration 6 -- 96: % %s s 97: -- Iteration 7 -- 98: one two three four 99: ===DONE===