PageRenderTime 36ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/strings/printf_64bit.php

http://github.com/facebook/hiphop-php
PHP | 215 lines | 210 code | 4 blank | 1 comment | 0 complexity | b542b2aa651da375454732eb011b7464 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. <?php
  2. /* Various input arrays for different format types */
  3. $float_variation = array( "%f", "%-f", "%+f", "%7.2f", "%-7.2f", "%07.2f", "%-07.2f", "%'#7.2f" );
  4. $float_numbers = array( 0, 1, -1, 0.32, -0.32, 3.4. -3.4, 2.54, -2.54, 1.2345678e99, -1.2345678e99 );
  5. $int_variation = array( "%d", "%-d", "%+d", "%7.2d", "%-7.2d", "%07.2d", "%-07.2d", "%'#7.2d" );
  6. $int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );
  7. $char_variation = array( 'a', "a", 67, -67, 99 );
  8. $string_variation = array( "%5s", "%-5s", "%05s", "%'#5s" );
  9. $strings = array( NULL, "abc", 'aaa' );
  10. /* Checking warning messages */
  11. /* Zero argument */
  12. echo "\n*** Output for zero argument ***\n";
  13. printf();
  14. /* Number of arguments not matching as specified in format field */
  15. echo "\n*** Output for insufficient number of arguments ***\n";
  16. $string = "dingy%sflem%dwombat";
  17. $nbr = 5;
  18. $name = "voudras";
  19. printf("%d $string %s", $nbr, $name);
  20. /* Scalar argument */
  21. echo "\n*** Output for scalar argument ***\n";
  22. printf(3);
  23. /* NULL argument */
  24. echo "\n*** Output for NULL as argument ***\n";
  25. printf(NULL);
  26. /* Float type variations */
  27. $counter = 1;
  28. echo "\n\n*** Output for float type ***\n";
  29. echo "\n Input Float numbers variation array is:\n";
  30. print_r($float_numbers);
  31. foreach( $float_variation as $float_var )
  32. {
  33. echo "\n\nFloat Iteration $counter";
  34. foreach( $float_numbers as $float_num )
  35. {
  36. echo "\n";
  37. printf( $float_var, $float_num );
  38. }
  39. $counter++;
  40. }
  41. /* Integer type variations */
  42. $counter = 1;
  43. echo "\n\n*** Output for integer type ***\n";
  44. echo "\n Input Integer numbers variation array is:\n";
  45. print_r($int_numbers);
  46. foreach( $int_variation as $int_var )
  47. {
  48. echo "\n\nInteger Iteration $counter";
  49. foreach( $int_numbers as $int_num )
  50. {
  51. echo "\n";
  52. printf( $int_var, $int_num );
  53. }
  54. $counter++;
  55. }
  56. /* Binary type variations */
  57. echo "\n\n*** Output for binary type ***\n";
  58. echo "\n Input numbers variation array is:\n";
  59. print_r($int_numbers);
  60. foreach( $int_numbers as $bin_num )
  61. {
  62. echo "\n";
  63. printf( "%b", $bin_num );
  64. }
  65. /* Chararter type variations */
  66. echo "\n\n*** Output for char type ***\n";
  67. echo "\n Input Characters variation array is:\n";
  68. print_r($char_variation);
  69. foreach( $char_variation as $char )
  70. {
  71. echo "\n";
  72. printf( "%c", $char );
  73. }
  74. /* Scientific type variations */
  75. echo "\n\n*** Output for scientific type ***\n";
  76. echo "\n Input numbers variation array is:\n";
  77. print_r($int_numbers);
  78. foreach( $int_numbers as $num )
  79. {
  80. echo "\n";
  81. printf( "%e", $num );
  82. }
  83. /* Unsigned Integer type variation */
  84. echo "\n\n*** Output for unsigned integer type ***\n";
  85. echo "\n Input Integer numbers variation array is:\n";
  86. print_r($int_numbers);
  87. foreach( $int_numbers as $unsig_num )
  88. {
  89. echo "\n";
  90. printf( "%u", $unsig_num );
  91. }
  92. /* Octal type variations */
  93. echo "\n\n*** Output for octal type ***\n";
  94. echo "\n Input numbers variation array is:\n";
  95. print_r($int_numbers);
  96. foreach( $int_numbers as $octal_num )
  97. {
  98. echo "\n";
  99. printf( "%o", $octal_num );
  100. }
  101. /* Hexadecimal type variations */
  102. echo "\n\n*** Output for hexadecimal type ***\n";
  103. echo "\n Input numbers variation array is:\n";
  104. print_r($int_numbers);
  105. foreach( $int_numbers as $hexa_num )
  106. {
  107. echo "\n";
  108. printf( "%x", $hexa_num );
  109. }
  110. /* String type variations */
  111. echo "\n\n*** Output for string type ***\n";
  112. echo "\n Input Strings format variation array is:\n";
  113. print_r($string_variation);
  114. echo "\n Input strings variation array is:\n";
  115. print_r($strings);
  116. foreach( $string_variation as $string_var )
  117. {
  118. foreach( $strings as $str )
  119. {
  120. echo "\n";
  121. printf( $string_var, $str );
  122. }
  123. }
  124. /* variations of %g type */
  125. $format_g = array("%g", "%.0g", "%+g", "%-g", "%-1.2g", "%+1.2g", "%G", "%.0G", "%+G", "%-G", "%-1.2G", "%+1.2G");
  126. echo "\n\n*** Output for '%g' type ***\n";
  127. echo "\n Input format variation array is:\n";
  128. print_r($format_g);
  129. foreach( $format_g as $formatg )
  130. {
  131. printf("\n$formatg",123456);
  132. printf("\n$formatg",-123456);
  133. }
  134. /* Some more typical cases */
  135. $tempnum = 12345;
  136. $tempstring = "abcdefghjklmnpqrstuvwxyz";
  137. echo"\n\n*** Output for '%%%.2f' as the format parameter ***\n";
  138. printf("%%%.2f",1.23456789e10);
  139. echo"\n\n*** Output for '%%' as the format parameter ***\n";
  140. printf("%%",1.23456789e10);
  141. echo"\n\n*** Output for precision value more than maximum ***\n";
  142. printf("%.988f",1.23456789e10);
  143. echo"\n\n*** Output for invalid width(-15) specifier ***\n";
  144. printf("%030.-15s", $tempstring);
  145. echo"\n\n*** Output for '%F' as the format parameter ***\n";
  146. printf("%F",1.23456789e10);
  147. echo"\n\n*** Output for '%X' as the format parameter ***\n";
  148. printf("%X",12);
  149. echo"\n\n*** Output with no format parameter ***\n";
  150. printf($tempnum);
  151. echo"\n\n*** Output for multiple format parameters ***\n";
  152. printf("%d %s %d\n", $tempnum, $tempstring, $tempnum);
  153. echo"\n\n*** Output for excess of mixed type arguments ***\n";
  154. printf("%s", $tempstring, $tempstring, $tempstring);
  155. echo"\n\n*** Output for string format parameter and integer type argument ***\n";
  156. printf("%s", $tempnum);
  157. echo"\n\n*** Output for integer format parameter and string type argument ***\n";
  158. printf("%d", $tempstring);
  159. ?>