1--TEST-- 2Test vfprintf() function : basic functionality 3--CREDITS-- 4Felix De Vliegher <felix.devliegher@gmail.com> 5--INI-- 6precision=14 7--FILE-- 8<?php 9/* Prototype : int vfprintf(resource stream, string format, array args) 10 * Description: Output a formatted string into a stream 11 * Source code: ext/standard/formatted_print.c 12 * Alias to functions: 13 */ 14 15function writeAndDump($fp, $format, $args) 16{ 17 ftruncate( $fp, 0 ); 18 $length = vfprintf( $fp, $format, $args ); 19 rewind( $fp ); 20 $content = stream_get_contents( $fp ); 21 var_dump( $content ); 22 var_dump( $length ); 23} 24 25echo "*** Testing vfprintf() : basic functionality ***\n"; 26 27// Open handle 28$file = 'vfprintf_test.txt'; 29$fp = fopen( $file, "a+" ); 30 31// Test vfprintf() 32writeAndDump( $fp, "Foo is %d and %s", array( 30, 'bar' ) ); 33writeAndDump( $fp, "%s %s %s", array( 'bar', 'bar', 'bar' ) ); 34writeAndDump( $fp, "%d digit", array( '54' ) ); 35writeAndDump( $fp, "%b %b", array( true, false ) ); 36writeAndDump( $fp, "%c %c %c", array( 65, 66, 67 ) ); 37writeAndDump( $fp, "%e %E %e", array( 1000, 2e4, +2e2 ) ); 38writeAndDump( $fp, "%02d", array( 50 ) ); 39writeAndDump( $fp, "Testing %b %d %f %s %x %X", array( 9, 6, 2.5502, "foobar", 15, 65 ) ); 40 41// Close handle 42fclose( $fp ); 43 44?> 45===DONE=== 46--CLEAN-- 47<?php 48 49$file = 'vfprintf_test.txt'; 50unlink( $file ); 51 52?> 53--EXPECTF-- 54*** Testing vfprintf() : basic functionality *** 55string(17) "Foo is 30 and bar" 56int(17) 57string(11) "bar bar bar" 58int(11) 59string(8) "54 digit" 60int(8) 61string(3) "1 0" 62int(3) 63string(5) "A B C" 64int(5) 65string(35) "1.000000e+3 2.000000E+4 2.000000e+2" 66int(35) 67string(2) "50" 68int(2) 69string(35) "Testing 1001 6 2.550200 foobar f 41" 70int(35) 71===DONE=== 72