PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/strings/vfprintf_variation9.php

http://github.com/facebook/hiphop-php
PHP | 61 lines | 38 code | 10 blank | 13 comment | 1 complexity | 53eabefe0a5eb5ca94f13055a359725e MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. /* Prototype : int vfprintf ( resource $handle , string $format , array $args )
  3. * Description: Write a formatted string to a stream
  4. * Source code: ext/standard/formatted_print.c
  5. */
  6. /*
  7. * Test vfprintf() for char formats with an array of chars passed to the function
  8. */
  9. <<__EntryPoint>> function main(): void {
  10. echo "*** Testing vfprintf() : char formats with char values ***\n";
  11. // defining array of char formats
  12. $formats = varray[
  13. "%c",
  14. "%+c %-c %C",
  15. "%lc %Lc, %4c %-4c",
  16. "%10.4c %-10.4c %04c %04.4c",
  17. "%'#2c %'2c %'$2c %'_2c",
  18. "%c %c %c %c",
  19. "% %%c c%",
  20. '%3$c %4$c %1$c %2$c'
  21. ];
  22. // Arrays of char values for the format defined in $format.
  23. // Each sub array contains char values which correspond to each format string in $format
  24. $args_array = varray[
  25. varray[0],
  26. varray['c', 67, 68],
  27. varray[' ', " ", -67, +67],
  28. varray[97, -97, 98, +98],
  29. varray[97, -97, 98, +98],
  30. varray[0x123b, 0xfAb, 0123, 01293],
  31. varray[38, -1234, 2345],
  32. varray[67, 68, 65, 66]
  33. ];
  34. /* creating dumping file */
  35. $data_file = dirname(__FILE__) . '/vfprintf_variation9.txt';
  36. if (!($fp = fopen($data_file, 'wt')))
  37. return;
  38. // looping to test vfprintf() with different char formats from the above $format array
  39. // and with char values from the above $args_array array
  40. $counter = 1;
  41. foreach($formats as $format) {
  42. fprintf($fp, "\n-- Iteration %d --\n",$counter);
  43. vfprintf($fp, $format, $args_array[$counter-1]);
  44. $counter++;
  45. }
  46. fclose($fp);
  47. print_r(file_get_contents($data_file));
  48. echo "\n";
  49. unlink($data_file);
  50. echo "===DONE===\n";
  51. }