1--TEST--
2Test vfprintf() function : usage variations - scientific formats with scientific values
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 scientific formats and scientific values
12 * are passed to the '$format' and '$args' arguments of the function
13*/
14
15echo "*** Testing vfprintf() : scientific formats and scientific values ***\n";
16
17// defining array of scientific formats
18$formats = array(
19  '%e %+e %-e',
20  '%le %Le %4e %-4e',
21  '%10.4e %-10.4e %.4e',
22  '%\'#20e %\'20e %\'$20e %\'_20e',
23  '%3$e %4$e %1$e %2$e'
24);
25
26// Arrays of scientific values for the format defined in $format.
27// Each sub array contains scientific values which correspond to each format string in $format
28$args_array = array(
29  array(0, 1e0, "10e2" ),
30  array(2.2e2, 10e10, 1000e-2, 1000e7),
31  array(-22e12, 10e20, 1.2e2),
32  array(1e1, +1e2, -1e3, "1e2_"),
33  array(3e3, 4e3, 1e3, 2e3)
34);
35
36/* creating dumping file */
37$data_file = dirname(__FILE__) . '/dump.txt';
38if (!($fp = fopen($data_file, 'wt')))
39   return;
40
41// looping to test vfprintf() with different scientific formats from the above $format array
42// and with signed and other types of  values from the above $args_array array
43$counter = 1;
44foreach($formats as $format) {
45  fprintf($fp, "\n-- Iteration %d --\n",$counter);
46  vfprintf($fp, $format, $args_array[$counter-1]);
47  $counter++;
48}
49
50fclose($fp);
51print_r(file_get_contents($data_file));
52echo "\n";
53
54unlink($data_file);
55?>
56===DONE===
57--EXPECT--
58*** Testing vfprintf() : scientific formats and scientific values ***
59
60-- Iteration 1 --
610.000000e+0 +1.000000e+0 1.000000e+3
62-- Iteration 2 --
632.200000e+2 e 1.000000e+1 1.000000e+10
64-- Iteration 3 --
65-2.2000e+13 1.0000e+21 1.2000e+2
66-- Iteration 4 --
67#########1.000000e+1 1.000000e+2 $$$$$$$$-1.000000e+3 _________1.000000e+2
68-- Iteration 5 --
691.000000e+3 2.000000e+3 3.000000e+3 4.000000e+3
70===DONE===
71