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

Variables

$list [{'key': 0, 'value': 'aaa,bbb'}, {'key': 1, 'value': 'aaa,"bbb"'}, {'key': 2, 'value': '"aaa","bbb"'}, {'key': 3, 'value': 'aaa,bbb'}, {'key': 4, 'value': '"aaa",bbb'}, {'key': 5, 'value': '"aaa", "bbb"'}, {'key': 6, 'value': ','}, {'key': 7, 'value': 'aaa,'}, {'key': 8, 'value': ',"aaa"'}, {'key': 9, 'value': '"",""'}, {'key': 10, 'value': '"""""",'}, {'key': 11, 'value': '""""",aaa'}, {'key': 12, 'value': 'aaa,bbb '}, {'key': 13, 'value': 'aaa,"bbb "'}, {'key': 14, 'value': 'aaa"aaa","bbb"bbb'}, {'key': 15, 'value': 'aaa"aaa""",bbb'}, {'key': 16, 'value': 'aaa,"/"bbb,ccc'}, {'key': 17, 'value': 'aaa"/"a","bbb"'}, {'key': 18, 'value': '"/"","aaa"'}, {'key': 19, 'value': '"/""",aaa'}]

Stats

MD5 a8b9a47420509a4ec47b7f790fbcf99e
Eval Count 0
Decode Time 123 ms