123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701 |
- --TEST--
- Test printf() function (32bit)
- --INI--
- precision=14
- --SKIPIF--
- <?php
- if (PHP_INT_MAX > 2147483647) {
- die("skip 32bit test only");
- }
- ?>
- --FILE--
- <?php
- /* Various input arrays for different format types */
- $float_variation = array( "%f", "%-f", "%+f", "%7.2f", "%-7.2f", "%07.2f", "%-07.2f", "%'#7.2f" );
- $float_numbers = array( 0, 1, -1, 0.32, -0.32, 3.4. -3.4, 2.54, -2.54, 1.2345678e99, -1.2345678e99 );
- $int_variation = array( "%d", "%-d", "%+d", "%7.2d", "%-7.2d", "%07.2d", "%-07.2d", "%'#7.2d" );
- $int_numbers = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );
- $char_variation = array( 'a', "a", 67, -67, 99 );
- $string_variation = array( "%5s", "%-5s", "%05s", "%'#5s" );
- $strings = array( NULL, "abc", 'aaa' );
- /* Checking warning messages */
- /* Zero argument */
- echo "\n*** Output for zero argument ***\n";
- try {
- printf();
- } catch (TypeError $e) {
- echo $e->getMessage(), "\n";
- }
- /* Number of arguments not matching as specified in format field */
- echo "\n*** Output for insufficient number of arguments ***\n";
- $string = "dingy%sflem%dwombat";
- $nbr = 5;
- $name = "voudras";
- try {
- printf("%d $string %s", $nbr, $name);
- } catch (\ArgumentCountError $e) {
- print('Error found: '.$e->getMessage());
- }
- /* Scalar argument */
- echo "\n*** Output for scalar argument ***\n";
- printf(3);
- /* Float type variations */
- $counter = 1;
- echo "\n\n*** Output for float type ***\n";
- echo "\n Input Float numbers variation array is:\n";
- print_r($float_numbers);
- foreach( $float_variation as $float_var )
- {
- echo "\n\nFloat Iteration $counter";
- foreach( $float_numbers as $float_num )
- {
- echo "\n";
- printf( $float_var, $float_num );
- }
- $counter++;
- }
- /* Integer type variations */
- $counter = 1;
- echo "\n\n*** Output for integer type ***\n";
- echo "\n Input Integer numbers variation array is:\n";
- print_r($int_numbers);
- foreach( $int_variation as $int_var )
- {
- echo "\n\nInteger Iteration $counter";
- foreach( $int_numbers as $int_num )
- {
- echo "\n";
- printf( $int_var, $int_num );
- }
- $counter++;
- }
- /* Binary type variations */
- echo "\n\n*** Output for binary type ***\n";
- echo "\n Input numbers variation array is:\n";
- print_r($int_numbers);
- foreach( $int_numbers as $bin_num )
- {
- echo "\n";
- printf( "%b", $bin_num );
- }
- /* Chararter type variations */
- echo "\n\n*** Output for char type ***\n";
- echo "\n Input Characters variation array is:\n";
- print_r($char_variation);
- foreach( $char_variation as $char )
- {
- echo "\n";
- printf( "%c", $char );
- }
- /* Scientific type variations */
- echo "\n\n*** Output for scientific type ***\n";
- echo "\n Input numbers variation array is:\n";
- print_r($int_numbers);
- foreach( $int_numbers as $num )
- {
- echo "\n";
- printf( "%e", $num );
- }
- /* Unsigned Integer type variation */
- echo "\n\n*** Output for unsigned integer type ***\n";
- echo "\n Input Integer numbers variation array is:\n";
- print_r($int_numbers);
- foreach( $int_numbers as $unsig_num )
- {
- echo "\n";
- printf( "%u", $unsig_num );
- }
- /* Octal type variations */
- echo "\n\n*** Output for octal type ***\n";
- echo "\n Input numbers variation array is:\n";
- print_r($int_numbers);
- foreach( $int_numbers as $octal_num )
- {
- echo "\n";
- printf( "%o", $octal_num );
- }
- /* Hexadecimal type variations */
- echo "\n\n*** Output for hexadecimal type ***\n";
- echo "\n Input numbers variation array is:\n";
- print_r($int_numbers);
- foreach( $int_numbers as $hexa_num )
- {
- echo "\n";
- printf( "%x", $hexa_num );
- }
- /* String type variations */
- echo "\n\n*** Output for string type ***\n";
- echo "\n Input Strings format variation array is:\n";
- print_r($string_variation);
- echo "\n Input strings variation array is:\n";
- print_r($strings);
- foreach( $string_variation as $string_var )
- {
- foreach( $strings as $str )
- {
- echo "\n";
- printf( $string_var, $str );
- }
- }
- /* variations of %g type */
- $format_g = array("%g", "%.0g", "%+g", "%-g", "%-1.2g", "%+1.2g", "%G", "%.0G", "%+G", "%-G", "%-1.2G", "%+1.2G");
- echo "\n\n*** Output for '%g' type ***\n";
- echo "\n Input format variation array is:\n";
- print_r($format_g);
- foreach( $format_g as $formatg )
- {
- printf("\n$formatg",123456);
- printf("\n$formatg",-123456);
- }
- /* Some more typical cases */
- $tempnum = 12345;
- $tempstring = "abcdefghjklmnpqrstuvwxyz";
- echo"\n\n*** Output for '%%%.2f' as the format parameter ***\n";
- printf("%%%.2f",1.23456789e10);
- echo"\n\n*** Output for '%%' as the format parameter ***\n";
- printf("%%",1.23456789e10);
- echo"\n\n*** Output for precision value more than maximum ***\n";
- printf("%.988f",1.23456789e10);
- echo"\n\n*** Output for invalid width(-15) specifier ***\n";
- try {
- printf("%030.-15s", $tempstring);
- } catch (ValueError $e) {
- echo $e->getMessage();
- }
- echo"\n\n*** Output for '%F' as the format parameter ***\n";
- printf("%F",1.23456789e10);
- echo"\n\n*** Output for '%X' as the format parameter ***\n";
- printf("%X",12);
- echo"\n\n*** Output with no format parameter ***\n";
- printf($tempnum);
- echo"\n\n*** Output for multiple format parameters ***\n";
- printf("%d %s %d\n", $tempnum, $tempstring, $tempnum);
- echo"\n\n*** Output for excess of mixed type arguments ***\n";
- printf("%s", $tempstring, $tempstring, $tempstring);
- echo"\n\n*** Output for string format parameter and integer type argument ***\n";
- printf("%s", $tempnum);
- echo"\n\n*** Output for integer format parameter and string type argument ***\n";
- printf("%d", $tempstring);
- ?>
- --EXPECTF--
- *** Output for zero argument ***
- printf() expects at least %d argument, %d given
- *** Output for insufficient number of arguments ***
- Error found: 5 arguments are required, 3 given
- *** Output for scalar argument ***
- 3
- *** Output for float type ***
- Input Float numbers variation array is:
- Array
- (
- [0] => 0
- [1] => 1
- [2] => -1
- [3] => 0.32
- [4] => -0.32
- [5] => 3.4-3.4
- [6] => 2.54
- [7] => -2.54
- [8] => 1.2345678E+99
- [9] => -1.2345678E+99
- )
- Float Iteration 1
- 0.000000
- 1.000000
- -1.000000
- 0.320000
- -0.320000
- 3.400000
- 2.540000
- -2.540000
- 1234567%d.000000
- -1234567%d.000000
- Float Iteration 2
- 0.000000
- 1.000000
- -1.000000
- 0.320000
- -0.320000
- 3.400000
- 2.540000
- -2.540000
- 1234567%d.000000
- -1234567%d.000000
- Float Iteration 3
- +0.000000
- +1.000000
- -1.000000
- +0.320000
- -0.320000
- +3.400000
- +2.540000
- -2.540000
- +1234567%d.000000
- -1234567%d.000000
- Float Iteration 4
- 0.00
- 1.00
- -1.00
- 0.32
- -0.32
- 3.40
- 2.54
- -2.54
- 1234567%d.00
- -1234567%d.00
- Float Iteration 5
- 0.00
- 1.00
- -1.00
- 0.32
- -0.32
- 3.40
- 2.54
- -2.54
- 1234567%d.00
- -1234567%d.00
- Float Iteration 6
- 0000.00
- 0001.00
- -001.00
- 0000.32
- -000.32
- 0003.40
- 0002.54
- -002.54
- 1234567%d.00
- -1234567%d.00
- Float Iteration 7
- 0.00000
- 1.00000
- -1.0000
- 0.32000
- -0.3200
- 3.40000
- 2.54000
- -2.5400
- 1234567%d.00
- -1234567%d.00
- Float Iteration 8
- ###0.00
- ###1.00
- ##-1.00
- ###0.32
- ##-0.32
- ###3.40
- ###2.54
- ##-2.54
- 1234567%d.00
- -1234567%d.00
- *** Output for integer type ***
- Input Integer numbers variation array is:
- Array
- (
- [0] => 0
- [1] => 1
- [2] => -1
- [3] => 2.7
- [4] => -2.7
- [5] => 23333333
- [6] => -23333333
- [7] => 1234
- )
- Integer Iteration 1
- 0
- 1
- -1
- 2
- -2
- 23333333
- -23333333
- 1234
- Integer Iteration 2
- 0
- 1
- -1
- 2
- -2
- 23333333
- -23333333
- 1234
- Integer Iteration 3
- +0
- +1
- -1
- +2
- -2
- +23333333
- -23333333
- +1234
- Integer Iteration 4
- 0
- 1
- -1
- 2
- -2
- 23333333
- -23333333
- 1234
- Integer Iteration 5
- 0
- 1
- -1
- 2
- -2
- 23333333
- -23333333
- 1234
- Integer Iteration 6
- 0000000
- 0000001
- -000001
- 0000002
- -000002
- 23333333
- -23333333
- 0001234
- Integer Iteration 7
- 0
- 1
- -1
- 2
- -2
- 23333333
- -23333333
- 1234
- Integer Iteration 8
- ######0
- ######1
- #####-1
- ######2
- #####-2
- 23333333
- -23333333
- ###1234
- *** Output for binary type ***
- Input numbers variation array is:
- Array
- (
- [0] => 0
- [1] => 1
- [2] => -1
- [3] => 2.7
- [4] => -2.7
- [5] => 23333333
- [6] => -23333333
- [7] => 1234
- )
- 0
- 1
- 11111111111111111111111111111111
- 10
- 11111111111111111111111111111110
- 1011001000000100111010101
- 11111110100110111111011000101011
- 10011010010
- *** Output for char type ***
- Input Characters variation array is:
- Array
- (
- [0] => a
- [1] => a
- [2] => 67
- [3] => -67
- [4] => 99
- )
- %0
- %0
- C
- ½
- c
- *** Output for scientific type ***
- Input numbers variation array is:
- Array
- (
- [0] => 0
- [1] => 1
- [2] => -1
- [3] => 2.7
- [4] => -2.7
- [5] => 23333333
- [6] => -23333333
- [7] => 1234
- )
- 0.000000e+0
- 1.000000e+0
- -1.000000e+0
- 2.700000e+0
- -2.700000e+0
- 2.333333e+7
- -2.333333e+7
- 1.234000e+3
- *** Output for unsigned integer type ***
- Input Integer numbers variation array is:
- Array
- (
- [0] => 0
- [1] => 1
- [2] => -1
- [3] => 2.7
- [4] => -2.7
- [5] => 23333333
- [6] => -23333333
- [7] => 1234
- )
- 0
- 1
- 4294967295
- 2
- 4294967294
- 23333333
- 4271633963
- 1234
- *** Output for octal type ***
- Input numbers variation array is:
- Array
- (
- [0] => 0
- [1] => 1
- [2] => -1
- [3] => 2.7
- [4] => -2.7
- [5] => 23333333
- [6] => -23333333
- [7] => 1234
- )
- 0
- 1
- 37777777777
- 2
- 37777777776
- 131004725
- 37646773053
- 2322
- *** Output for hexadecimal type ***
- Input numbers variation array is:
- Array
- (
- [0] => 0
- [1] => 1
- [2] => -1
- [3] => 2.7
- [4] => -2.7
- [5] => 23333333
- [6] => -23333333
- [7] => 1234
- )
- 0
- 1
- ffffffff
- 2
- fffffffe
- 16409d5
- fe9bf62b
- 4d2
- *** Output for string type ***
- Input Strings format variation array is:
- Array
- (
- [0] => %5s
- [1] => %-5s
- [2] => %r%%r05s
- [3] => %'#5s
- )
- Input strings variation array is:
- Array
- (
- [0] =>
- [1] => abc
- [2] => aaa
- )
-
- abc
- aaa
-
- abc
- aaa
- 00000
- 00abc
- 00aaa
- #####
- ##abc
- ##aaa
- *** Output for '%g' type ***
- Input format variation array is:
- Array
- (
- [0] => %g
- [1] => %.0g
- [2] => %+g
- [3] => %-g
- [4] => %-1.2g
- [5] => %+1.2g
- [6] => %G
- [7] => %.0G
- [8] => %+G
- [9] => %-G
- [10] => %-1.2G
- [11] => %+1.2G
- )
- 123456
- -123456
- 1.0e+5
- -1.0e+5
- +123456
- -123456
- 123456
- -123456
- 1.2e+5
- -1.2e+5
- +1.2e+5
- -1.2e+5
- 123456
- -123456
- 1.0E+5
- -1.0E+5
- +123456
- -123456
- 123456
- -123456
- 1.2E+5
- -1.2E+5
- +1.2E+5
- -1.2E+5
- *** Output for '%%%.2f' as the format parameter ***
- %12345678900.00
- *** Output for '%%' as the format parameter ***
- %
- *** Output for precision value more than maximum ***
- Notice: printf(): Requested precision of 988 digits was truncated to PHP maximum of 53 digits in %s on line %d
- 12345678900.00000000000000000000000000000000000000000000000000000
- *** Output for invalid width(-15) specifier ***
- Unknown format specifier "-"
- *** Output for '%F' as the format parameter ***
- 12345678900.000000
- *** Output for '%X' as the format parameter ***
- C
- *** Output with no format parameter ***
- 12345
- *** Output for multiple format parameters ***
- 12345 abcdefghjklmnpqrstuvwxyz 12345
- *** Output for excess of mixed type arguments ***
- abcdefghjklmnpqrstuvwxyz
- *** Output for string format parameter and integer type argument ***
- 12345
- *** Output for integer format parameter and string type argument ***
- 0
|