Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
--TEST-- Test fscanf() function: usage variations - unsigned formats with strings --FILE--..
Decoded Output download
--TEST--
Test fscanf() function: usage variations - unsigned formats with strings
--FILE--
<?php
/* Test fscanf() to scan strings using different unsigned format types */
$file_path = __DIR__;
echo "*** Test fscanf(): different unsigned format types with strings ***
";
// create a file
$filename = "$file_path/fscanf_variation43.tmp";
$file_handle = fopen($filename, "w");
if($file_handle == false)
exit("Error:failed to open file $filename");
// array of strings
$strings = array (
"",
'',
"0",
'0',
"1",
'1',
"",
'',
"",
'',
'string',
"string",
"true",
"FALSE",
'false',
'TRUE',
"NULL",
'null'
);
$unsigned_formats = array( "%u", "%hu", "%lu", "%Lu", " %u", "%u ", "% u", " %u", "
%u", "%4u", "%30u", "%[0-9]", "%*u");
$counter = 1;
// writing to the file
foreach($strings as $string) {
@fprintf($file_handle, $string);
@fprintf($file_handle, "
");
}
// closing the file
fclose($file_handle);
// opening the file for reading
$file_handle = fopen($filename, "r");
if($file_handle == false) {
exit("Error:failed to open file $filename");
}
$counter = 1;
// reading the values from file using different unsigned formats
foreach($unsigned_formats as $unsigned_format) {
// rewind the file so that for every foreach iteration the file pointer starts from bof
rewind($file_handle);
echo "
-- iteration $counter --
";
while( !feof($file_handle) ) {
try {
var_dump(fscanf($file_handle,$unsigned_format));
} catch (ValueError $exception) {
echo $exception->getMessage() . "
";
}
}
$counter++;
}
echo "
*** Done ***";
?>
--CLEAN--
<?php
$file_path = __DIR__;
$filename = "$file_path/fscanf_variation43.tmp";
unlink($filename);
?>
--EXPECT--
*** Test fscanf(): different unsigned format types with strings ***
-- iteration 1 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 2 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 3 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 4 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 5 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 6 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 7 --
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
bool(false)
-- iteration 8 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 9 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 10 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 11 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 12 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
string(1) "0"
}
array(1) {
[0]=>
string(1) "0"
}
array(1) {
[0]=>
string(1) "1"
}
array(1) {
[0]=>
string(1) "1"
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 13 --
NULL
NULL
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
bool(false)
*** Done ***
Did this file decode correctly?
Original Code
--TEST--
Test fscanf() function: usage variations - unsigned formats with strings
--FILE--
<?php
/* Test fscanf() to scan strings using different unsigned format types */
$file_path = __DIR__;
echo "*** Test fscanf(): different unsigned format types with strings ***\n";
// create a file
$filename = "$file_path/fscanf_variation43.tmp";
$file_handle = fopen($filename, "w");
if($file_handle == false)
exit("Error:failed to open file $filename");
// array of strings
$strings = array (
"",
'',
"0",
'0',
"1",
'1',
"\x01",
'\x01',
"\01",
'\01',
'string',
"string",
"true",
"FALSE",
'false',
'TRUE',
"NULL",
'null'
);
$unsigned_formats = array( "%u", "%hu", "%lu", "%Lu", " %u", "%u ", "% u", "\t%u", "\n%u", "%4u", "%30u", "%[0-9]", "%*u");
$counter = 1;
// writing to the file
foreach($strings as $string) {
@fprintf($file_handle, $string);
@fprintf($file_handle, "\n");
}
// closing the file
fclose($file_handle);
// opening the file for reading
$file_handle = fopen($filename, "r");
if($file_handle == false) {
exit("Error:failed to open file $filename");
}
$counter = 1;
// reading the values from file using different unsigned formats
foreach($unsigned_formats as $unsigned_format) {
// rewind the file so that for every foreach iteration the file pointer starts from bof
rewind($file_handle);
echo "\n-- iteration $counter --\n";
while( !feof($file_handle) ) {
try {
var_dump(fscanf($file_handle,$unsigned_format));
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
}
$counter++;
}
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = __DIR__;
$filename = "$file_path/fscanf_variation43.tmp";
unlink($filename);
?>
--EXPECT--
*** Test fscanf(): different unsigned format types with strings ***
-- iteration 1 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 2 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 3 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 4 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 5 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 6 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 7 --
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
Bad scan conversion character " "
bool(false)
-- iteration 8 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 9 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 10 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 11 --
NULL
NULL
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(0)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
int(1)
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 12 --
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
string(1) "0"
}
array(1) {
[0]=>
string(1) "0"
}
array(1) {
[0]=>
string(1) "1"
}
array(1) {
[0]=>
string(1) "1"
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
array(1) {
[0]=>
NULL
}
bool(false)
-- iteration 13 --
NULL
NULL
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
array(0) {
}
bool(false)
*** Done ***
Function Calls
None |
Stats
MD5 | 79ab1f63cda353da882e83c4c7209511 |
Eval Count | 0 |
Decode Time | 91 ms |