php-src/ext/standard/tests/strings/sprintf_variation5.phpt

74 lines
1.3 KiB
Plaintext
Raw Normal View History

2007-09-29 14:15:53 +00:00
--TEST--
Test sprintf() function : usage variations - int formats with resource values
--FILE--
<?php
/* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]])
* Description: Return a formatted string
* Source code: ext/standard/formatted_print.c
*/
echo "*** Testing sprintf() : integer formats with resource values ***\n";
// resource type variable
$fp = fopen (__FILE__, "r");
$dfp = opendir ( dirname(__FILE__) );
2007-12-24 04:29:26 +00:00
$fp_copy = $fp;
$dfp_copy = $dfp;
2007-09-29 14:15:53 +00:00
// array of resource types
$resource_types = array (
2007-12-24 04:29:26 +00:00
$fp_copy,
$dfp_copy
2007-09-29 14:15:53 +00:00
);
// various integer formats
$int_formats = array(
"%d", "%Ld", " %d",
"\t%d", "\n%d", "%4d",
"%[0-9]", "%*d"
);
$count = 1;
foreach($resource_types as $res) {
echo "\n-- Iteration $count --\n";
foreach($int_formats as $format) {
var_dump( sprintf($format, $res) );
}
$count++;
};
// closing the resources
fclose($fp);
2007-12-24 04:29:26 +00:00
closedir($dfp);
2007-09-29 14:15:53 +00:00
echo "Done";
?>
--EXPECTF--
*** Testing sprintf() : integer formats with resource values ***
-- Iteration 1 --
unicode(%d) "%d"
unicode(1) "d"
unicode(%d) " %d"
unicode(%d) " %d"
unicode(%d) "
%d"
2007-12-24 04:29:26 +00:00
unicode(%d) "%s%d"
unicode(%d) "0-9]"
2007-09-29 14:15:53 +00:00
unicode(1) "d"
-- Iteration 2 --
unicode(%d) "%d"
unicode(1) "d"
unicode(%d) " %d"
unicode(%d) " %d"
unicode(%d) "
%d"
2007-12-24 04:29:26 +00:00
unicode(%d) "%s%d"
unicode(%d) "0-9]"
2007-09-29 14:15:53 +00:00
unicode(1) "d"
Done