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-- various fputcsv() functionality tests --CREDITS-- Lee Leathers <leeleathers@gmail..
Decoded Output download
--TEST--
various fputcsv() functionality tests
--CREDITS--
Lee Leathers <[email protected]>
--FILE--
<?php
$list = array (
0 => 'aaa,bbb',
1 => 'aaa,"bbb"',
2 => '"aaa","bbb"',
3 => 'aaa,bbb',
4 => '"aaa",bbb',
5 => '"aaa", "bbb"',
6 => ',',
7 => 'aaa,',
8 => ',"aaa"',
9 => '"",""',
10 => '"""""",',
11 => '""""",aaa',
12 => 'aaa,bbb ',
13 => 'aaa,"bbb "',
14 => 'aaa"aaa","bbb"bbb',
15 => 'aaa"aaa""",bbb',
16 => 'aaa,"/"bbb,ccc',
17 => 'aaa"/"a","bbb"',
18 => '"/"","aaa"',
19 => '"/""",aaa',
);
$file = __DIR__ . '/fputcsv_variation15.csv';
@unlink($file);
$fp = fopen($file, "w");
foreach ($list as $v) {
fputcsv($fp, explode(',', $v), ',', '"', '/');
}
fclose($fp);
$res = file($file);
foreach($res as &$val)
{
$val = substr($val, 0, -1);
}
echo '$list = ';var_export($res);echo ";
";
$fp = fopen($file, "r");
$res = array();
while($l=fgetcsv($fp, 0, ',', '"', '/'))
{
$res[] = join(',',$l);
}
fclose($fp);
echo '$list = ';var_export($res);echo ";
";
@unlink($file);
?>
--EXPECT--
$list = array (
0 => 'aaa,bbb',
1 => 'aaa,"""bbb"""',
2 => '"""aaa""","""bbb"""',
3 => 'aaa,bbb',
4 => '"""aaa""",bbb',
5 => '"""aaa"""," ""bbb"""',
6 => ',',
7 => 'aaa,',
8 => ',"""aaa"""',
9 => '"""""",""""""',
10 => '"""""""""""""",',
11 => '"""""""""""",aaa',
12 => 'aaa,"bbb "',
13 => 'aaa,"""bbb """',
14 => '"aaa""aaa""","""bbb""bbb"',
15 => '"aaa""aaa""""""",bbb',
16 => 'aaa,"""/"bbb",ccc',
17 => '"aaa""/"a""","""bbb"""',
18 => '"""/"""","""aaa"""',
19 => '"""/"""""",aaa',
);
$list = array (
0 => 'aaa,bbb',
1 => 'aaa,"bbb"',
2 => '"aaa","bbb"',
3 => 'aaa,bbb',
4 => '"aaa",bbb',
5 => '"aaa", "bbb"',
6 => ',',
7 => 'aaa,',
8 => ',"aaa"',
9 => '"",""',
10 => '"""""",',
11 => '""""",aaa',
12 => 'aaa,bbb ',
13 => 'aaa,"bbb "',
14 => 'aaa"aaa","bbb"bbb',
15 => 'aaa"aaa""",bbb',
16 => 'aaa,"/"bbb,ccc',
17 => 'aaa"/"a","bbb"',
18 => '"/"","aaa"',
19 => '"/""",aaa',
);
Did this file decode correctly?
Original Code
--TEST--
various fputcsv() functionality tests
--CREDITS--
Lee Leathers <[email protected]>
--FILE--
<?php
$list = array (
0 => 'aaa,bbb',
1 => 'aaa,"bbb"',
2 => '"aaa","bbb"',
3 => 'aaa,bbb',
4 => '"aaa",bbb',
5 => '"aaa", "bbb"',
6 => ',',
7 => 'aaa,',
8 => ',"aaa"',
9 => '"",""',
10 => '"""""",',
11 => '""""",aaa',
12 => 'aaa,bbb ',
13 => 'aaa,"bbb "',
14 => 'aaa"aaa","bbb"bbb',
15 => 'aaa"aaa""",bbb',
16 => 'aaa,"/"bbb,ccc',
17 => 'aaa"/"a","bbb"',
18 => '"/"","aaa"',
19 => '"/""",aaa',
);
$file = __DIR__ . '/fputcsv_variation15.csv';
@unlink($file);
$fp = fopen($file, "w");
foreach ($list as $v) {
fputcsv($fp, explode(',', $v), ',', '"', '/');
}
fclose($fp);
$res = file($file);
foreach($res as &$val)
{
$val = substr($val, 0, -1);
}
echo '$list = ';var_export($res);echo ";\n";
$fp = fopen($file, "r");
$res = array();
while($l=fgetcsv($fp, 0, ',', '"', '/'))
{
$res[] = join(',',$l);
}
fclose($fp);
echo '$list = ';var_export($res);echo ";\n";
@unlink($file);
?>
--EXPECT--
$list = array (
0 => 'aaa,bbb',
1 => 'aaa,"""bbb"""',
2 => '"""aaa""","""bbb"""',
3 => 'aaa,bbb',
4 => '"""aaa""",bbb',
5 => '"""aaa"""," ""bbb"""',
6 => ',',
7 => 'aaa,',
8 => ',"""aaa"""',
9 => '"""""",""""""',
10 => '"""""""""""""",',
11 => '"""""""""""",aaa',
12 => 'aaa,"bbb "',
13 => 'aaa,"""bbb """',
14 => '"aaa""aaa""","""bbb""bbb"',
15 => '"aaa""aaa""""""",bbb',
16 => 'aaa,"""/"bbb",ccc',
17 => '"aaa""/"a""","""bbb"""',
18 => '"""/"""","""aaa"""',
19 => '"""/"""""",aaa',
);
$list = array (
0 => 'aaa,bbb',
1 => 'aaa,"bbb"',
2 => '"aaa","bbb"',
3 => 'aaa,bbb',
4 => '"aaa",bbb',
5 => '"aaa", "bbb"',
6 => ',',
7 => 'aaa,',
8 => ',"aaa"',
9 => '"",""',
10 => '"""""",',
11 => '""""",aaa',
12 => 'aaa,bbb ',
13 => 'aaa,"bbb "',
14 => 'aaa"aaa","bbb"bbb',
15 => 'aaa"aaa""",bbb',
16 => 'aaa,"/"bbb,ccc',
17 => 'aaa"/"a","bbb"',
18 => '"/"","aaa"',
19 => '"/""",aaa',
);
Function Calls
None |
Stats
MD5 | a8b9a47420509a4ec47b7f790fbcf99e |
Eval Count | 0 |
Decode Time | 123 ms |