fscanf_variation10.phpt [plain text]
--TEST--
Test fscanf() function: usage variations - float formats with resource
--FILE--
<?php
$file_path = dirname(__FILE__);
echo "*** Test fscanf(): different float format types with resource ***\n";
$filename = "$file_path/fscanf_variation10.tmp";
$file_handle = fopen($filename, "w");
if($file_handle == false)
exit("Error:failed to open file $filename");
$fp = fopen (__FILE__, "r");
$dfp = opendir ( dirname(__FILE__) );
$resource_types = array (
$fp,
$dfp
);
$float_formats = array( "%f",
"%hf", "%lf", "%Lf",
" %f", "%f ", "% f",
"\t%f", "\n%f", "%4f",
"%30f", "%[0-9]", "%*f"
);
$counter = 1;
foreach($resource_types as $value) {
@fprintf($file_handle, $value);
@fprintf($file_handle, "\n");
}
fclose($file_handle);
$file_handle = fopen($filename, "r");
if($file_handle == false) {
exit("Error:failed to open file $filename");
}
$counter = 1;
foreach($float_formats as $float_format) {
rewind($file_handle);
echo "\n-- iteration $counter --\n";
while( !feof($file_handle) ) {
var_dump( fscanf($file_handle,$float_format) );
}
$counter++;
}
fclose($fp);
closedir($dfp);
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
$filename = "$file_path/fscanf_variation10.tmp";
unlink($filename);
?>
--EXPECTF--
*** Test fscanf(): different float format types with resource ***
-- iteration 1 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 2 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 3 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 4 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 5 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 6 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 7 --
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
NULL
Warning: fscanf(): Bad scan conversion character " " in %s on line %d
NULL
bool(false)
-- iteration 8 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 9 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 10 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 11 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 12 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 13 --
array(0) {
}
array(0) {
}
bool(false)
*** Done ***