<?php
$csv = <<<CSV
"Price","Bogus","Symbol","Description","Qty (Quantity)","Price Chng % (Price Change %)","Price Chng $ (Price Change $)","Day Chng % (Day Change %)","Day Chng $ (Day Change $)","Cost Basis","Gain % (Gain/Loss %)","Gain $ (Gain/Loss $)","Reinvest?","Reinvest Capital Gains?","Last Div (Last Dividend)","Volume","Security Type"
"$19.39","foo1","Test1","ETF","820","-2.42%","-$0.48","-2.42%","-$393.6","$601.73","-18.89%","-$3701.93","No","--","$0.72025","14,626,464","ETFs & Closed End Funds"
"$49.43","foo2","Test2"," ETF","110","-2.39%","-$1.21","-2.39%","-$133.1","$995.2","-9.31%","-$557.9","Yes","--","N/A","59,351,095","ETFs & Closed End Funds"
"$21.77","foo3","Test3"," ETF","760","-3.72%","-$0.84","-3.72%","-$638.4","$687.73","-20.02%","-$142.53","No","--","$2.0216","6,402,084","ETFs & Closed End Funds"
CSV;
$handle = tmpfile();
fwrite($handle, $csv);
rewind($handle);
$whitelist = [
"Symbol",
"Description",
"Qty (Quantity)",
"Price",
"Price Chng % (Price Change %)",
"Price Chng $ (Price Change $)",
"Day Chng % (Day Change %)",
"Day Chng $ (Day Change $)",
"Cost Basis",
"Gain % (Gain/Loss %)",
"Gain $ (Gain/Loss $)",
"Reinvest?",
"Reinvest Capital Gains?",
"Last Div (Last Dividend)",
"Volume",
"Security Type"
];
$headers = fgetcsv($handle, null, ',', '"', '') ?: [];
$map = array_flip($headers);
$result = [];
while (($values = fgetcsv($handle, null, ',', '"', '')) !== false) {
$row = [];
foreach ($whitelist as $col) {
$row[$col] = $values[$map[$col]] ?? null;
}
$result[] = $row;
}
fclose($handle);
var_export($result);
- Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array (
0 =>
array (
'Symbol' => 'Test1',
'Description' => 'ETF',
'Qty (Quantity)' => '820',
'Price' => '$19.39',
'Price Chng % (Price Change %)' => '-2.42%',
'Price Chng $ (Price Change $)' => '-$0.48',
'Day Chng % (Day Change %)' => '-2.42%',
'Day Chng $ (Day Change $)' => '-$393.6',
'Cost Basis' => '$601.73',
'Gain % (Gain/Loss %)' => '-18.89%',
'Gain $ (Gain/Loss $)' => '-$3701.93',
'Reinvest?' => 'No',
'Reinvest Capital Gains?' => '--',
'Last Div (Last Dividend)' => '$0.72025',
'Volume' => '14,626,464',
'Security Type' => 'ETFs & Closed End Funds',
),
1 =>
array (
'Symbol' => 'Test2',
'Description' => ' ETF',
'Qty (Quantity)' => '110',
'Price' => '$49.43',
'Price Chng % (Price Change %)' => '-2.39%',
'Price Chng $ (Price Change $)' => '-$1.21',
'Day Chng % (Day Change %)' => '-2.39%',
'Day Chng $ (Day Change $)' => '-$133.1',
'Cost Basis' => '$995.2',
'Gain % (Gain/Loss %)' => '-9.31%',
'Gain $ (Gain/Loss $)' => '-$557.9',
'Reinvest?' => 'Yes',
'Reinvest Capital Gains?' => '--',
'Last Div (Last Dividend)' => 'N/A',
'Volume' => '59,351,095',
'Security Type' => 'ETFs & Closed End Funds',
),
2 =>
array (
'Symbol' => 'Test3',
'Description' => ' ETF',
'Qty (Quantity)' => '760',
'Price' => '$21.77',
'Price Chng % (Price Change %)' => '-3.72%',
'Price Chng $ (Price Change $)' => '-$0.84',
'Day Chng % (Day Change %)' => '-3.72%',
'Day Chng $ (Day Change $)' => '-$638.4',
'Cost Basis' => '$687.73',
'Gain % (Gain/Loss %)' => '-20.02%',
'Gain $ (Gain/Loss $)' => '-$142.53',
'Reinvest?' => 'No',
'Reinvest Capital Gains?' => '--',
'Last Div (Last Dividend)' => '$2.0216',
'Volume' => '6,402,084',
'Security Type' => 'ETFs & Closed End Funds',
),
)
- Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33
- Warning: fgetcsv(): escape must be character in /in/DFMRo on line 33
Warning: fgetcsv(): escape must be character in /in/DFMRo on line 37
array (
)
- Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
- Parse error: syntax error, unexpected '?' in /in/DFMRo on line 40
Process exited with code 255. - Output for 4.4.3 - 4.4.9, 5.1.0 - 5.1.1, 5.1.3 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected '[' in /in/DFMRo on line 14
Process exited with code 255. - Output for 4.4.2, 5.1.2
- Parse error: syntax error, unexpected '[' in /in/DFMRo on line 15
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected '[' in /in/DFMRo on line 14
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/DFMRo on line 14
Process exited with code 255.
preferences:
117.4 ms | 415 KiB | 5 Q